New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPCS Config Refresh #4867

Merged
merged 5 commits into from Jul 31, 2018

Conversation

2 participants
@GaryJones
Contributor

GaryJones commented Jul 26, 2018

See individual commits for more info.

Self-note: WP-CLI is pinned to PHP 5.3.29, so it's PHP_Codesniffer 2.9.1 that is installed. As such parallel and basepath args are not available.

Note, that none of the newly reported violations have yet been fixed in this PR, but I can do if desired. 374 violations are auto-fixable (mostly whitespace), and two are the use of eval (1, 2).

Here's the source summary of violations:

> ~/code/wp-cli: phpcs --report=source
WW.W.W...W..................WWWWW.WW.W.WWW....E.W.W.WWWE...E 60 / 69 (87%)
WWE.WWW.W


PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
----------------------------------------------------------------------
    SOURCE                                                       COUNT
----------------------------------------------------------------------
[x] Generic.Formatting.MultipleStatementAlignment.NotSameWarnin  207
[x] WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotA  161
[x] Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceA  2
[ ] Squiz.PHP.Eval.Discouraged                                   2
[x] WordPress.WhiteSpace.ArbitraryParenthesesSpacing.SpaceBefor  1
[x] WordPress.WhiteSpace.ArbitraryParenthesesSpacing.SpaceAfter  1
[x] Generic.Functions.FunctionCallArgumentSpacing.SpaceBeforeCo  1
[x] Generic.Formatting.MultipleStatementAlignment.IncorrectWarn  1
----------------------------------------------------------------------
A TOTAL OF 376 SNIFF VIOLATIONS WERE FOUND IN 8 SOURCES
----------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SOURCES AUTOMATICALLY (374 VIOLATIONS IN TOTAL)
----------------------------------------------------------------------

Time: 9.35 secs; Memory: 30Mb
@schlessera

This comment has been minimized.

Show comment
Hide comment
@schlessera

schlessera Jul 30, 2018

Member

@GaryJones would you be up to adding the needed fix in an additional commit? Both the PHPCBF automatic fixes, and the ignore for the eval uses.

Member

schlessera commented Jul 30, 2018

@GaryJones would you be up to adding the needed fix in an additional commit? Both the PHPCBF automatic fixes, and the ignore for the eval uses.

GaryJones added some commits Jul 26, 2018

PHPCS: Refresh config
- Clarify that this is a custom ruleset, not a standard.
- Add descriptive comments with URL references for further information
- Move the scan arguments (How to scan) just above the rulesets and custom properties (also defines how to scan)
- Adds `colors` arg for those operating systems that support it.
- Remove reports, which should only be decided at runtime. Default report is full.
PHPCS: Autofix most violations
Mostly whitespace-only changes, with a couple of multi-lie function calls having parameters split over multiple lines.
PHPCS: Ignore known uses of eval()
- For PHPCS 3+, this will just ignore the `eval()` call.
- For PHPCS 2.x, the whole line is ignore for all possible violations.
@GaryJones

This comment has been minimized.

Show comment
Hide comment
@GaryJones

GaryJones Jul 31, 2018

Contributor

Done.

Note, that this is only for WordPress-Core. If WordPress-Extra is enabled, then these are the additional violations:

PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
----------------------------------------------------------------------
    SOURCE                                                       COUNT
----------------------------------------------------------------------
[ ] WordPress.PHP.StrictComparisons.LooseComparison              37
[ ] WordPress.CodeAnalysis.AssignmentInCondition.Found           23
[ ] WordPress.PHP.StrictInArray.MissingTrueStrict                19
[ ] WordPress.Security.EscapeOutput.OutputNotEscaped             14
[ ] WordPress.WP.AlternativeFunctions.json_encode_json_encode    13
[ ] WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration  10
[ ] WordPress.WP.GlobalVariablesOverride.OverrideProhibited      10
[x] WordPress.Classes.ClassInstantiation.MissingParenthesis      9
[ ] WordPress.WP.AlternativeFunctions.file_get_contents_file_ge  9
[ ] WordPress.WP.AlternativeFunctions.file_system_read_fwrite    8
[x] Squiz.Classes.SelfMemberReference.NotUsed                    6
[ ] WordPress.WP.DiscouragedConstants.UsageFound                 6
[ ] WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration  5
[ ] WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_  5
[ ] WordPress.WP.AlternativeFunctions.file_system_read_fclose    5
[ ] WordPress.WP.AlternativeFunctions.parse_url_parse_url        5
[ ] WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCo  3
[ ] WordPress.PHP.DevelopmentFunctions.error_log_trigger_error   3
[ ] WordPress.WP.AlternativeFunctions.file_system_read_fopen     3
[ ] WordPress.WP.AlternativeFunctions.strip_tags_strip_tags      3
[ ] WordPress.WP.AlternativeFunctions.file_system_read_file_put  2
[ ] WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration  2
[ ] WordPress.PHP.DevelopmentFunctions.error_log_var_export      2
[ ] Generic.CodeAnalysis.UselessOverridingMethod.Found           2
[ ] WordPress.WP.AlternativeFunctions.rand_mt_rand               2
[ ] PSR2.Methods.MethodDeclaration.Underscore                    2
[x] PSR2.Namespaces.NamespaceDeclaration.BlankLineAfter          1
[x] PEAR.Files.IncludingFile.UseRequireOnce                      1
[ ] WordPress.WP.TimezoneChange.timezone_change_date_default_ti  1
[ ] WordPress.CodeAnalysis.AssignmentInCondition.FoundInTernary  1
[ ] WordPress.PHP.DevelopmentFunctions.error_log_debug_print_ba  1
[ ] WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_ex  1
[ ] WordPress.PHP.DiscouragedPHPFunctions.system_calls_proc_ope  1
[ ] Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed  1
[ ] WordPress.PHP.DiscouragedPHPFunctions.system_calls_passthru  1
[ ] WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode    1
[ ] WordPress.WP.AlternativeFunctions.curl_curl_errno            1
[ ] Generic.Strings.UnnecessaryStringConcat.Found                1
[ ] Squiz.PHP.DisallowSizeFunctionsInLoops.Found                 1
[ ] Squiz.Scope.MethodScope.Missing                              1
----------------------------------------------------------------------
A TOTAL OF 222 SNIFF VIOLATIONS WERE FOUND IN 40 SOURCES
----------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SOURCES AUTOMATICALLY (17 VIOLATIONS IN TOTAL)
----------------------------------------------------------------------

If WordPress-Docs is added in (which although not complete to the Handbook, does highlight some easy-to-miss items), these are the extra violations:


PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
----------------------------------------------------------------------
    SOURCE                                                       COUNT
----------------------------------------------------------------------
[ ] Squiz.Commenting.InlineComment.InvalidEndChar                121
[ ] Squiz.Commenting.FunctionComment.MissingParamTag             84
[ ] Squiz.Commenting.FunctionComment.Missing                     83
[ ] Squiz.Commenting.FunctionComment.MissingParamComment         81
[ ] Squiz.Commenting.FunctionComment.ParamCommentFullStop        66
[ ] Squiz.Commenting.FileComment.Missing                         62
[x] Squiz.Commenting.FunctionComment.SpacingAfterParamType       51
[ ] Generic.Commenting.DocComment.MissingShort                   51
[ ] Squiz.Commenting.VariableComment.Missing                     48
[ ] Squiz.Commenting.FunctionComment.MissingParamName            23
[ ] Squiz.Commenting.FunctionComment.ParamNameNoMatch            13
[x] Generic.Commenting.DocComment.SpacingBeforeTags              10
[ ] Squiz.Commenting.FunctionCommentThrowTag.Missing             10
[x] Squiz.Commenting.InlineComment.WrongStyle                    8
[ ] Squiz.Commenting.FunctionComment.InvalidNoReturn             7
[ ] Squiz.Commenting.FileComment.WrongStyle                      6
[ ] Generic.Commenting.DocComment.ShortNotCapital                5
[ ] Squiz.Commenting.FunctionComment.WrongStyle                  5
[ ] Squiz.PHP.CommentedOutCode.Found                             5
[x] Squiz.Commenting.InlineComment.SpacingAfter                  4
[ ] Squiz.Commenting.ClassComment.Missing                        4
[ ] Squiz.Commenting.FunctionComment.ExtraParamComment           2
[ ] Squiz.Commenting.VariableComment.MissingVar                  2
[x] Squiz.Commenting.BlockComment.NoNewLine                      1
[x] Squiz.Commenting.InlineComment.Empty                         1
[ ] Squiz.Commenting.FileComment.MissingPackageTag               1
[ ] Squiz.Commenting.VariableComment.WrongStyle                  1
----------------------------------------------------------------------
A TOTAL OF 755 SNIFF VIOLATIONS WERE FOUND IN 27 SOURCES
----------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SOURCES AUTOMATICALLY (75 VIOLATIONS IN TOTAL)
----------------------------------------------------------------------
Contributor

GaryJones commented Jul 31, 2018

Done.

Note, that this is only for WordPress-Core. If WordPress-Extra is enabled, then these are the additional violations:

PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
----------------------------------------------------------------------
    SOURCE                                                       COUNT
----------------------------------------------------------------------
[ ] WordPress.PHP.StrictComparisons.LooseComparison              37
[ ] WordPress.CodeAnalysis.AssignmentInCondition.Found           23
[ ] WordPress.PHP.StrictInArray.MissingTrueStrict                19
[ ] WordPress.Security.EscapeOutput.OutputNotEscaped             14
[ ] WordPress.WP.AlternativeFunctions.json_encode_json_encode    13
[ ] WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration  10
[ ] WordPress.WP.GlobalVariablesOverride.OverrideProhibited      10
[x] WordPress.Classes.ClassInstantiation.MissingParenthesis      9
[ ] WordPress.WP.AlternativeFunctions.file_get_contents_file_ge  9
[ ] WordPress.WP.AlternativeFunctions.file_system_read_fwrite    8
[x] Squiz.Classes.SelfMemberReference.NotUsed                    6
[ ] WordPress.WP.DiscouragedConstants.UsageFound                 6
[ ] WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration  5
[ ] WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_  5
[ ] WordPress.WP.AlternativeFunctions.file_system_read_fclose    5
[ ] WordPress.WP.AlternativeFunctions.parse_url_parse_url        5
[ ] WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCo  3
[ ] WordPress.PHP.DevelopmentFunctions.error_log_trigger_error   3
[ ] WordPress.WP.AlternativeFunctions.file_system_read_fopen     3
[ ] WordPress.WP.AlternativeFunctions.strip_tags_strip_tags      3
[ ] WordPress.WP.AlternativeFunctions.file_system_read_file_put  2
[ ] WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration  2
[ ] WordPress.PHP.DevelopmentFunctions.error_log_var_export      2
[ ] Generic.CodeAnalysis.UselessOverridingMethod.Found           2
[ ] WordPress.WP.AlternativeFunctions.rand_mt_rand               2
[ ] PSR2.Methods.MethodDeclaration.Underscore                    2
[x] PSR2.Namespaces.NamespaceDeclaration.BlankLineAfter          1
[x] PEAR.Files.IncludingFile.UseRequireOnce                      1
[ ] WordPress.WP.TimezoneChange.timezone_change_date_default_ti  1
[ ] WordPress.CodeAnalysis.AssignmentInCondition.FoundInTernary  1
[ ] WordPress.PHP.DevelopmentFunctions.error_log_debug_print_ba  1
[ ] WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_ex  1
[ ] WordPress.PHP.DiscouragedPHPFunctions.system_calls_proc_ope  1
[ ] Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed  1
[ ] WordPress.PHP.DiscouragedPHPFunctions.system_calls_passthru  1
[ ] WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode    1
[ ] WordPress.WP.AlternativeFunctions.curl_curl_errno            1
[ ] Generic.Strings.UnnecessaryStringConcat.Found                1
[ ] Squiz.PHP.DisallowSizeFunctionsInLoops.Found                 1
[ ] Squiz.Scope.MethodScope.Missing                              1
----------------------------------------------------------------------
A TOTAL OF 222 SNIFF VIOLATIONS WERE FOUND IN 40 SOURCES
----------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SOURCES AUTOMATICALLY (17 VIOLATIONS IN TOTAL)
----------------------------------------------------------------------

If WordPress-Docs is added in (which although not complete to the Handbook, does highlight some easy-to-miss items), these are the extra violations:


PHP CODE SNIFFER VIOLATION SOURCE SUMMARY
----------------------------------------------------------------------
    SOURCE                                                       COUNT
----------------------------------------------------------------------
[ ] Squiz.Commenting.InlineComment.InvalidEndChar                121
[ ] Squiz.Commenting.FunctionComment.MissingParamTag             84
[ ] Squiz.Commenting.FunctionComment.Missing                     83
[ ] Squiz.Commenting.FunctionComment.MissingParamComment         81
[ ] Squiz.Commenting.FunctionComment.ParamCommentFullStop        66
[ ] Squiz.Commenting.FileComment.Missing                         62
[x] Squiz.Commenting.FunctionComment.SpacingAfterParamType       51
[ ] Generic.Commenting.DocComment.MissingShort                   51
[ ] Squiz.Commenting.VariableComment.Missing                     48
[ ] Squiz.Commenting.FunctionComment.MissingParamName            23
[ ] Squiz.Commenting.FunctionComment.ParamNameNoMatch            13
[x] Generic.Commenting.DocComment.SpacingBeforeTags              10
[ ] Squiz.Commenting.FunctionCommentThrowTag.Missing             10
[x] Squiz.Commenting.InlineComment.WrongStyle                    8
[ ] Squiz.Commenting.FunctionComment.InvalidNoReturn             7
[ ] Squiz.Commenting.FileComment.WrongStyle                      6
[ ] Generic.Commenting.DocComment.ShortNotCapital                5
[ ] Squiz.Commenting.FunctionComment.WrongStyle                  5
[ ] Squiz.PHP.CommentedOutCode.Found                             5
[x] Squiz.Commenting.InlineComment.SpacingAfter                  4
[ ] Squiz.Commenting.ClassComment.Missing                        4
[ ] Squiz.Commenting.FunctionComment.ExtraParamComment           2
[ ] Squiz.Commenting.VariableComment.MissingVar                  2
[x] Squiz.Commenting.BlockComment.NoNewLine                      1
[x] Squiz.Commenting.InlineComment.Empty                         1
[ ] Squiz.Commenting.FileComment.MissingPackageTag               1
[ ] Squiz.Commenting.VariableComment.WrongStyle                  1
----------------------------------------------------------------------
A TOTAL OF 755 SNIFF VIOLATIONS WERE FOUND IN 27 SOURCES
----------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SOURCES AUTOMATICALLY (75 VIOLATIONS IN TOTAL)
----------------------------------------------------------------------

@schlessera schlessera added this to the 2.0.0 milestone Jul 31, 2018

@schlessera schlessera merged commit dd8da5e into wp-cli:master Jul 31, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@GaryJones GaryJones deleted the GaryJones:phpcs-config branch Aug 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment