Skip to content
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

Coding standards #191

Open
nylen opened this issue Jan 22, 2020 · 2 comments
Open

Coding standards #191

nylen opened this issue Jan 22, 2020 · 2 comments

Comments

@nylen
Copy link
Contributor

nylen commented Jan 22, 2020

As of #190 the coding standards checks on every PR are disabled. This is because the coding standards checks run whenever a file is changed in a PR against that whole file, but there are many pre-existing standards violations, for example: https://travis-ci.com/ClassicPress-research/classic-commerce/jobs/278382606

The Woo team fixes these as they go along, but this isn't something we want to do (lots of extra work, makes PRs messier). Future approaches to fix this could include:

  • cleaning up the codebase for one rule at a time (like tabs vs spaces) then enabling only those rules against new PRs
  • cleaning up all the issues at once (huge amount of work)
@timbocode
Copy link
Contributor

Tabs vs spaces might be a good one to start with using PHPCBF.

@nylen
Copy link
Contributor Author

nylen commented Jan 22, 2020

I used the following command to run phpcs on all PHP files:

git ls-files -z | grep -z '\.php$' | xargs -0 ./vendor/bin/phpcs --encoding=utf-8 -s -n -p | pv > cc-phpcs.txt

Results: https://nylen.io/cc-phpcs.txt

Total number of violations:

grep -P '^\s*\|\s*\|\s*\([^) ]+\)$' cc-phpcs.txt | sed 's/^.*(//; s/)$//' | wc -l
3985

Rules broken with number of violations per rule:

click to expand
grep -P '^\s*\|\s*\|\s*\([^) ]+\)$' cc-phpcs.txt | sed 's/^.*(//; s/)$//' | sort | uniq -c
     45 Core.Commenting.CommentTags.AccessTag
    120 Core.Commenting.CommentTags.AuthorTag
     42 Core.Commenting.CommentTags.CategoryTag
      1 Generic.CodeAnalysis.EmptyStatement.DetectedIf
      1 Generic.Commenting.DocComment.LongNotCapital
      2 Generic.Commenting.DocComment.MissingShort
     21 Generic.Commenting.DocComment.ShortNotCapital
     10 Generic.Commenting.DocComment.SpacingBeforeTags
      1 Generic.Files.EndFileNewline.NotFound
      2 Generic.Formatting.SpaceAfterCast.NoSpace
      1 Generic.Functions.FunctionCallArgumentSpacing.SpaceBeforeComma
      2 Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma
     15 Generic.PHP.ForbiddenFunctions.FoundWithAlternative
      1 Generic.Strings.UnnecessaryStringConcat.Found
     15 Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed
      9 Generic.WhiteSpace.ScopeIndent.Incorrect
     67 Generic.WhiteSpace.ScopeIndent.IncorrectExact
      1 PEAR.Functions.FunctionCallSignature.Indent
     99 PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket
     99 PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket
      1 PEAR.NamingConventions.ValidClassName.Invalid
      1 PHPCompatibility.Classes.NewClasses.phardataFound
      1 PHPCompatibility.Constants.NewConstants.debug_backtrace_ignore_argsFound
      3 PHPCompatibility.FunctionDeclarations.NewClosure.Found
      1 PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.Changed
      2 PHPCompatibility.FunctionUse.ArgumentFunctionsUsage.InParameterList
      2 PHPCompatibility.FunctionUse.NewFunctionParameters.round_modeFound
      1 PHPCompatibility.FunctionUse.NewFunctions.array_columnFound
      1 PHPCompatibility.FunctionUse.NewFunctions.array_replaceFound
      2 PHPCompatibility.FunctionUse.NewFunctions.gc_enableFound
      1 PHPCompatibility.Keywords.NewKeywords.t_constFound
      1 PHPCompatibility.Keywords.NewKeywords.t_namespaceFound
      4 PHPCompatibility.LanguageConstructs.NewEmptyNonVariable.Found
     15 PHPCompatibility.LanguageConstructs.NewLanguageConstructs.t_ns_separatorFound
      9 PHPCompatibility.ParameterValues.NewHTMLEntitiesEncodingDefault.NotSet
      7 PHPCompatibility.ParameterValues.NewIconvMbstringCharsetDefault.NotSet
     54 PHPCompatibility.Syntax.NewShortArray.Found
     18 PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonCASE
      3 PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonDEFAULT
      3 Squiz.Classes.SelfMemberReference.NotUsed
     15 Squiz.Commenting.BlockComment.HasEmptyLineBefore
      4 Squiz.Commenting.ClassComment.Missing
     19 Squiz.Commenting.ClassComment.SpacingAfter
     26 Squiz.Commenting.FileComment.Missing
     19 Squiz.Commenting.FileComment.MissingPackageTag
      9 Squiz.Commenting.FileComment.SpacingAfterComment
      2 Squiz.Commenting.FileComment.SpacingAfterOpen
      6 Squiz.Commenting.FunctionComment.EmptyThrows
      1 Squiz.Commenting.FunctionComment.InvalidNoReturn
      2 Squiz.Commenting.FunctionComment.InvalidReturnVoid
    222 Squiz.Commenting.FunctionComment.MissingParamComment
     16 Squiz.Commenting.FunctionComment.MissingParamName
     57 Squiz.Commenting.FunctionComment.MissingParamTag
     45 Squiz.Commenting.FunctionComment.ParamCommentFullStop
      5 Squiz.Commenting.FunctionComment.ParamNameNoMatch
     32 Squiz.Commenting.FunctionComment.SpacingAfterParamType
      7 Squiz.Commenting.FunctionCommentThrowTag.Missing
      1 Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
      4 Squiz.Commenting.FunctionComment.WrongStyle
    541 Squiz.Commenting.InlineComment.InvalidEndChar
      4 Squiz.Commenting.InlineComment.NoSpaceBefore
     20 Squiz.Commenting.VariableComment.Missing
      5 Squiz.Commenting.VariableComment.MissingVar
      3 Squiz.Commenting.VariableComment.WrongStyle
      3 Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace
      1 Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace
      2 Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword
      1 Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceAfterEquals
      1 Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeEquals
      6 Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen
     10 Squiz.PHP.DisallowMultipleAssignments.Found
     56 Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
      7 Squiz.PHP.EmbeddedPhp.ContentAfterEnd
     11 Squiz.PHP.EmbeddedPhp.ContentAfterOpen
      7 Squiz.PHP.EmbeddedPhp.ContentBeforeEnd
      7 Squiz.PHP.EmbeddedPhp.ContentBeforeOpen
     12 Squiz.PHP.EmbeddedPhp.NoSemicolon
      3 Squiz.PHP.EmbeddedPhp.SpacingBeforeClose
     85 Squiz.Scope.MethodScope.Missing
     72 Squiz.Strings.ConcatenationSpacing.PaddingFound
     15 Squiz.Strings.DoubleQuoteUsage.NotRequired
      5 Squiz.WhiteSpace.SuperfluousWhitespace.EndLine
      8 WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
     11 WordPress.Arrays.ArrayDeclarationSpacing.NoSpaceAfterArrayOpener
     11 WordPress.Arrays.ArrayDeclarationSpacing.NoSpaceBeforeArrayCloser
      1 WordPress.Arrays.ArrayIndentation.CloseBraceNotAligned
     23 WordPress.Arrays.ArrayKeySpacingRestrictions.NoSpacesAroundArrayKeys
      5 WordPress.Arrays.CommaAfterArrayItem.NoComma
      8 WordPress.Arrays.CommaAfterArrayItem.SpaceAfterComma
     30 WordPress.Classes.ClassInstantiation.MissingParenthesis
     33 WordPress.DateTime.CurrentTimeTimestamp.RequestedUTC
     65 WordPress.DateTime.RestrictedFunctions.date_date
     21 WordPress.DB.PreparedSQL.InterpolatedNotPrepared
     13 WordPress.DB.PreparedSQL.NotPrepared
      1 WordPress.Files.FileName.InvalidClassFileName
      3 WordPress.Files.FileName.NotHyphenatedLowercase
      1 WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
     15 WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
      2 WordPress.PHP.DontExtract.extract_extract
      1 WordPress.PHP.IniSet.display_errors_Blacklisted
      4 WordPress.PHP.TypeCasts.DoubleRealFound
     18 WordPress.PHP.YodaConditions.NotYoda
    345 WordPress.Security.EscapeOutput.OutputNotEscaped
    186 WordPress.Security.EscapeOutput.UnsafePrintingFunction
    240 WordPress.Security.NonceVerification.Missing
    130 WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
    174 WordPress.Security.ValidatedSanitizedInput.InputNotValidated
    213 WordPress.Security.ValidatedSanitizedInput.MissingUnslash
      2 WordPress.WhiteSpace.ControlStructureSpacing.BlankLineAfterEnd
     52 WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterOpenParenthesis
      2 WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterStructureOpen
     52 WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceBeforeCloseParenthesis
      2 WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceBeforeOpenParenthesis
     61 WordPress.WhiteSpace.DisallowInlineTabs.NonIndentTabsUsed
     25 WordPress.WhiteSpace.OperatorSpacing.NoSpaceAfter
     28 WordPress.WhiteSpace.OperatorSpacing.NoSpaceBefore
      1 WordPress.WhiteSpace.OperatorSpacing.SpacingAfter
      4 WordPress.WhiteSpace.OperatorSpacing.SpacingBefore
      1 WordPress.WP.DeprecatedParameters.Wp_upload_bitsParam2Found
      1 WordPress.WP.EnqueuedResourceParameters.MissingVersion
      1 WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet
     50 WordPress.WP.GlobalVariablesOverride.Prohibited
      4 WordPress.WP.I18n.MissingArgDomain
      3 WordPress.WP.I18n.MissingSingularPlaceholder
     81 WordPress.WP.I18n.MissingTranslatorsComment

Some of these can probably be ignored in phpcs.xml, some can probably be fixed and then enabled for future PRs. I think this should wait until after v1 since there is plenty more urgent work to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants