diff --git a/src/main/resources/docs/description/Drupal_Classes_UseGlobalClass.md b/src/main/resources/docs/description/Drupal_Classes_UseGlobalClass.md new file mode 100644 index 00000000..022bec50 --- /dev/null +++ b/src/main/resources/docs/description/Drupal_Classes_UseGlobalClass.md @@ -0,0 +1 @@ +Checks non-namespaced classes are referenced by FQN, not imported. \ No newline at end of file diff --git a/src/main/resources/docs/description/Drupal_Commenting_InlineVariableComment.md b/src/main/resources/docs/description/Drupal_Commenting_InlineVariableComment.md new file mode 100644 index 00000000..27597985 --- /dev/null +++ b/src/main/resources/docs/description/Drupal_Commenting_InlineVariableComment.md @@ -0,0 +1 @@ +Checks for the correct usage of inline variable type declarations. \ No newline at end of file diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_Arrays_MultiLineArrayEndBracketPlacement.md b/src/main/resources/docs/description/SlevomatCodingStandard_Arrays_MultiLineArrayEndBracketPlacement.md index 1535e8eb..7b3d991a 100644 --- a/src/main/resources/docs/description/SlevomatCodingStandard_Arrays_MultiLineArrayEndBracketPlacement.md +++ b/src/main/resources/docs/description/SlevomatCodingStandard_Arrays_MultiLineArrayEndBracketPlacement.md @@ -1,3 +1,3 @@ # SlevomatCodingStandard_Arrays_MultiLineArrayEndBracketPlacement -Enforces reasonable end bracket placement for multiline arrays. +Enforces reasonable end bracket placement for multi-line arrays. diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_Classes_SuperfluousErrorNaming.md b/src/main/resources/docs/description/SlevomatCodingStandard_Classes_SuperfluousErrorNaming.md new file mode 100644 index 00000000..4b1c909c --- /dev/null +++ b/src/main/resources/docs/description/SlevomatCodingStandard_Classes_SuperfluousErrorNaming.md @@ -0,0 +1,3 @@ +# SlevomatCodingStandard_Classes_SuperfluousErrorNaming + +Reports use of superfluous suffix "Error" for errors. diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_Classes_UnusedPrivateElements.md b/src/main/resources/docs/description/SlevomatCodingStandard_Classes_UnusedPrivateElements.md index 86a984af..7c38fc53 100644 --- a/src/main/resources/docs/description/SlevomatCodingStandard_Classes_UnusedPrivateElements.md +++ b/src/main/resources/docs/description/SlevomatCodingStandard_Classes_UnusedPrivateElements.md @@ -1,5 +1,8 @@ # SlevomatCodingStandard_Classes_UnusedPrivateElements +**DEPRECATED** +See https://phpstan.org/blog/detecting-unused-private-properties-methods-constants + Although PHP_CodeSniffer is not suitable for static analysis because it is limited to analysing one file at a time, it is possible to use it to perform certain checks. `UnusedPrivateElementsSniff` checks for unused methods, unused or write-only properties in a class and unused private constants. Reported unused elements are safe to remove. This is very useful during refactoring to clean up dead code and injected dependencies. diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_Commenting_DeprecatedAnnotationDeclaration.md b/src/main/resources/docs/description/SlevomatCodingStandard_Commenting_DeprecatedAnnotationDeclaration.md new file mode 100644 index 00000000..07e01bc3 --- /dev/null +++ b/src/main/resources/docs/description/SlevomatCodingStandard_Commenting_DeprecatedAnnotationDeclaration.md @@ -0,0 +1 @@ +Commenting: Deprecated Annotation Declaration \ No newline at end of file diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_Commenting_InlineDocCommentDeclaration.md b/src/main/resources/docs/description/SlevomatCodingStandard_Commenting_InlineDocCommentDeclaration.md index b66ad7a3..88c43b2b 100644 --- a/src/main/resources/docs/description/SlevomatCodingStandard_Commenting_InlineDocCommentDeclaration.md +++ b/src/main/resources/docs/description/SlevomatCodingStandard_Commenting_InlineDocCommentDeclaration.md @@ -5,3 +5,4 @@ Reports invalid inline phpDocs with `@var`. Sniff provides the following settings: * `allowDocCommentAboveReturn`: Allows documentation comments without variable name above `return` statemens. +* `allowAboveNonAssignment`: Allows documentation comments above non-assigment if the line contains the right variable name. diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_RequireMultiLineCondition.md b/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_RequireMultiLineCondition.md new file mode 100644 index 00000000..22adb159 --- /dev/null +++ b/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_RequireMultiLineCondition.md @@ -0,0 +1,10 @@ +# SlevomatCodingStandard_ControlStructures_RequireMultiLineCondition + +Enforces conditions of `if`, `elseif`, `while` and `do-while` with one or more boolean operators to be splitted to more lines +so each condition part is on its own line. + +Sniff provides the following settings: + +* `minLineLength`: specifies mininum line length to enforce condition to be splitted. Use 0 value to enforce for all conditions, regardless of length. +* `booleanOperatorOnPreviousLine`: boolean operator is placed at the end of previous line when fixing. +* `alwaysSplitAllConditionParts`: require all condition parts to be on its own line - it reports error even if condition is already multi-line but there are some condition parts on the same line. diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_RequireSingleLineCondition.md b/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_RequireSingleLineCondition.md new file mode 100644 index 00000000..c1c6a4be --- /dev/null +++ b/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_RequireSingleLineCondition.md @@ -0,0 +1,8 @@ +# SlevomatCodingStandard_ControlStructures_RequireSingleLineCondition + +Enforces conditions of `if`, `elseif`, `while` and `do-while` to be on a single line. + +Sniff provides the following settings: + +* `maxLineLength`: specifies max allowed line length. If conditition (and the rest of the line) would fit on it, it's enforced. Use 0 value to enforce for all conditions, regardless of length. +* `alwaysForSimpleConditions`: allows to enforce single line for all simple conditions (i.e no `&&`, `||` or `xor`), regardless of length. diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_RequireTernaryOperator.md b/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_RequireTernaryOperator.md index e6bfaf27..9dd616b8 100644 --- a/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_RequireTernaryOperator.md +++ b/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_RequireTernaryOperator.md @@ -4,4 +4,4 @@ Requires ternary operator when possible. Sniff provides the following settings: -* `ignoreMultiLine` (defaults to `false`): ignores multiLine statements. +* `ignoreMultiLine` (defaults to `false`): ignores multi-line statements. diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_UselessTernaryOperator.md b/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_UselessTernaryOperator.md index 09ec09cf..a98c6bbd 100644 --- a/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_UselessTernaryOperator.md +++ b/src/main/resources/docs/description/SlevomatCodingStandard_ControlStructures_UselessTernaryOperator.md @@ -18,7 +18,7 @@ The recommended way to install Slevomat Coding Standard is [through Composer](ht } ``` -It's also recommended to install [jakub-onderka/php-parallel-lint](https://github.com/JakubOnderka/PHP-Parallel-Lint) which checks source code for syntax errors. Sniffs count on the processed code to be syntactically valid (no parse errors), otherwise they can behave unexpectedly. It is advised to run `PHP-Parallel-Lint` in your build tool before running `PHP_CodeSniffer` and exiting the build process early if `PHP-Parallel-Lint` fails. +It's also recommended to install [php-parallel-lint/php-parallel-lint](https://github.com/php-parallel-lint/PHP-Parallel-Lint) which checks source code for syntax errors. Sniffs count on the processed code to be syntactically valid (no parse errors), otherwise they can behave unexpectedly. It is advised to run `PHP-Parallel-Lint` in your build tool before running `PHP_CodeSniffer` and exiting the build process early if `PHP-Parallel-Lint` fails. ## How to run the sniffs diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_Functions_ArrowFunctionDeclaration.md b/src/main/resources/docs/description/SlevomatCodingStandard_Functions_ArrowFunctionDeclaration.md index 6fa7a738..55934b70 100644 --- a/src/main/resources/docs/description/SlevomatCodingStandard_Functions_ArrowFunctionDeclaration.md +++ b/src/main/resources/docs/description/SlevomatCodingStandard_Functions_ArrowFunctionDeclaration.md @@ -7,4 +7,4 @@ Sniff provides the following settings: * `spacesCountAfterKeyword`: the number of spaces after `fn`. * `spacesCountBeforeArrow`: the number of spaces before `=>`. * `spacesCountAfterArrow`: the number of spaces after `=>`. -* `allowMultiLine`: allows multiline declaration. +* `allowMultiLine`: allows multi-line declaration. diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_Functions_RequireMultiLineCall.md b/src/main/resources/docs/description/SlevomatCodingStandard_Functions_RequireMultiLineCall.md new file mode 100644 index 00000000..45aff559 --- /dev/null +++ b/src/main/resources/docs/description/SlevomatCodingStandard_Functions_RequireMultiLineCall.md @@ -0,0 +1,7 @@ +# SlevomatCodingStandard_Functions_RequireMultiLineCall + +Enforces function call to be splitted to more lines so each parameter is on its own line. + +Sniff provides the following settings: + +* `minLineLength`: specifies min line length to enforce call to be splitted. Use 0 value to enforce for all calls, regardless of length. diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_Functions_RequireSingleLineCall.md b/src/main/resources/docs/description/SlevomatCodingStandard_Functions_RequireSingleLineCall.md new file mode 100644 index 00000000..669ba936 --- /dev/null +++ b/src/main/resources/docs/description/SlevomatCodingStandard_Functions_RequireSingleLineCall.md @@ -0,0 +1,8 @@ +# SlevomatCodingStandard_Functions_RequireSingleLineCall + +Enforces function call to be on a single line. + +Sniff provides the following settings: + +* `maxLineLength`: specifies max allowed line length. If call would fit on it, it's enforced. Use 0 value to enforce for all calls, regardless of length. +* `ignoreWithComplexParameter` (defaults to `true`): ignores calls with arrays, closures, arrow functions and nested calls. diff --git a/src/main/resources/docs/description/SlevomatCodingStandard_Whitespaces_DuplicateSpaces.md b/src/main/resources/docs/description/SlevomatCodingStandard_Whitespaces_DuplicateSpaces.md index 61c5fb4d..4d96418f 100644 --- a/src/main/resources/docs/description/SlevomatCodingStandard_Whitespaces_DuplicateSpaces.md +++ b/src/main/resources/docs/description/SlevomatCodingStandard_Whitespaces_DuplicateSpaces.md @@ -7,3 +7,4 @@ Sniff provides the following settings: * `ignoreSpacesBeforeAssignment`: to allow multiple spaces to align assignments. * `ignoreSpacesInAnnotation`: to allow multiple spaces to align annotations. * `ignoreSpacesInComment`: to allow multiple spaces to align content of the comment. +* `ignoreSpacesInParameters`: to allow multiple spaces to align parameters. diff --git a/src/main/resources/docs/description/description.json b/src/main/resources/docs/description/description.json index e901f3e1..9f49af2c 100644 --- a/src/main/resources/docs/description/description.json +++ b/src/main/resources/docs/description/description.json @@ -44,6 +44,10 @@ "patternId" : "Drupal_Classes_UnusedUseStatement", "title" : "Classes: Unused Use Statement", "description" : "Checks for \"use\" statements that are not needed in a file." +}, { + "patternId" : "Drupal_Classes_UseGlobalClass", + "title" : "Classes: Use Global Class", + "description" : "Checks non-namespaced classes are referenced by FQN, not imported." }, { "patternId" : "Drupal_Classes_UseLeadingBackslash", "title" : "Classes: Use Leading Backslash", @@ -91,6 +95,10 @@ }, { "patternId" : "Drupal_Commenting_InlineComment", "title" : "Commenting: Inline Comment" +}, { + "patternId" : "Drupal_Commenting_InlineVariableComment", + "title" : "Commenting: Inline Variable Comment", + "description" : "Checks for the correct usage of inline variable type declarations." }, { "patternId" : "Drupal_Commenting_PostStatementComment", "title" : "Commenting: Post Statement Comment", @@ -1981,6 +1989,9 @@ }, { "patternId" : "SlevomatCodingStandard_Classes_SuperfluousAbstractClassNaming", "title" : "Classes: Superfluous Abstract Class Naming" +}, { + "patternId" : "SlevomatCodingStandard_Classes_SuperfluousErrorNaming", + "title" : "Classes: Superfluous Error Naming" }, { "patternId" : "SlevomatCodingStandard_Classes_SuperfluousExceptionNaming", "title" : "Classes: Superfluous Exception Naming" @@ -2018,6 +2029,9 @@ }, { "patternId" : "SlevomatCodingStandard_Classes_UselessLateStaticBinding", "title" : "Classes: Useless Late Static Binding" +}, { + "patternId" : "SlevomatCodingStandard_Commenting_DeprecatedAnnotationDeclaration", + "title" : "Commenting: Deprecated Annotation Declaration" }, { "patternId" : "SlevomatCodingStandard_Commenting_DisallowCommentAfterCode", "title" : "Commenting: Disallow Comment After Code" @@ -2058,6 +2072,9 @@ "parameters" : [ { "name" : "allowDocCommentAboveReturn", "description" : "allowDocCommentAboveReturn" + }, { + "name" : "allowAboveNonAssignment", + "description" : "allowAboveNonAssignment" } ] }, { "patternId" : "SlevomatCodingStandard_Commenting_RequireOneLineDocComment", @@ -2160,6 +2177,19 @@ }, { "patternId" : "SlevomatCodingStandard_ControlStructures_NewWithoutParentheses", "title" : "Control Structures: New Without Parentheses" +}, { + "patternId" : "SlevomatCodingStandard_ControlStructures_RequireMultiLineCondition", + "title" : "Control Structures: Require Multi Line Condition", + "parameters" : [ { + "name" : "minLineLength", + "description" : "minLineLength" + }, { + "name" : "booleanOperatorOnPreviousLine", + "description" : "booleanOperatorOnPreviousLine" + }, { + "name" : "alwaysSplitAllConditionParts", + "description" : "alwaysSplitAllConditionParts" + } ] }, { "patternId" : "SlevomatCodingStandard_ControlStructures_RequireMultiLineTernaryOperator", "title" : "Control Structures: Require Multi Line Ternary Operator", @@ -2180,6 +2210,16 @@ }, { "patternId" : "SlevomatCodingStandard_ControlStructures_RequireShortTernaryOperator", "title" : "Control Structures: Require Short Ternary Operator" +}, { + "patternId" : "SlevomatCodingStandard_ControlStructures_RequireSingleLineCondition", + "title" : "Control Structures: Require Single Line Condition", + "parameters" : [ { + "name" : "maxLineLength", + "description" : "maxLineLength" + }, { + "name" : "alwaysForSimpleConditions", + "description" : "alwaysForSimpleConditions" + } ] }, { "patternId" : "SlevomatCodingStandard_ControlStructures_RequireTernaryOperator", "title" : "Control Structures: Require Ternary Operator", @@ -2262,6 +2302,23 @@ "name" : "enable", "description" : "enable" } ] +}, { + "patternId" : "SlevomatCodingStandard_Functions_RequireMultiLineCall", + "title" : "Functions: Require Multi Line Call", + "parameters" : [ { + "name" : "minLineLength", + "description" : "minLineLength" + } ] +}, { + "patternId" : "SlevomatCodingStandard_Functions_RequireSingleLineCall", + "title" : "Functions: Require Single Line Call", + "parameters" : [ { + "name" : "maxLineLength", + "description" : "maxLineLength" + }, { + "name" : "ignoreWithComplexParameter", + "description" : "ignoreWithComplexParameter" + } ] }, { "patternId" : "SlevomatCodingStandard_Functions_StaticClosure", "title" : "Functions: Static Closure" @@ -2584,6 +2641,9 @@ }, { "name" : "ignoreSpacesInComment", "description" : "ignoreSpacesInComment" + }, { + "name" : "ignoreSpacesInParameters", + "description" : "ignoreSpacesInParameters" } ] }, { "patternId" : "Squiz_Arrays_ArrayBracketSpacing", @@ -3268,15 +3328,8 @@ "description" : "Restricts usage of some server variables." }, { "patternId" : "WordPressVIPMinimum_Variables_VariableAnalysis", - "title" : "Variables: Variable Analysis", - "description" : "Checks the for undefined function variables.", - "parameters" : [ { - "name" : "allowUnusedCaughtExceptions", - "description" : "allowUnusedCaughtExceptions" - }, { - "name" : "allowUnusedFunctionParameters", - "description" : "allowUnusedFunctionParameters" - } ] + "title" : "Variables: Variable Analysis (Deprecated)", + "description" : "Checks the for undefined function variables." }, { "patternId" : "WordPress_Arrays_ArrayDeclarationSpacing", "title" : "Arrays: Array Declaration Spacing", diff --git a/src/main/resources/docs/multiple-tests/vip-wordpress/results.xml b/src/main/resources/docs/multiple-tests/vip-wordpress/results.xml index 073629ed..1f18c6b9 100644 --- a/src/main/resources/docs/multiple-tests/vip-wordpress/results.xml +++ b/src/main/resources/docs/multiple-tests/vip-wordpress/results.xml @@ -1,7 +1,6 @@ - diff --git a/src/main/resources/docs/multiple-tests/vip-wordpress/src/phpcs.xml b/src/main/resources/docs/multiple-tests/vip-wordpress/src/phpcs.xml index 292ba6f5..5ef843b0 100644 --- a/src/main/resources/docs/multiple-tests/vip-wordpress/src/phpcs.xml +++ b/src/main/resources/docs/multiple-tests/vip-wordpress/src/phpcs.xml @@ -6,6 +6,4 @@ error - - diff --git a/src/main/resources/docs/patterns.json b/src/main/resources/docs/patterns.json index 91185644..be98a8da 100644 --- a/src/main/resources/docs/patterns.json +++ b/src/main/resources/docs/patterns.json @@ -49,6 +49,10 @@ "patternId" : "Drupal_Classes_UnusedUseStatement", "level" : "Info", "category" : "CodeStyle" + }, { + "patternId" : "Drupal_Classes_UseGlobalClass", + "level" : "Info", + "category" : "CodeStyle" }, { "patternId" : "Drupal_Classes_UseLeadingBackslash", "level" : "Info", @@ -97,6 +101,10 @@ "patternId" : "Drupal_Commenting_InlineComment", "level" : "Info", "category" : "CodeStyle" + }, { + "patternId" : "Drupal_Commenting_InlineVariableComment", + "level" : "Info", + "category" : "CodeStyle" }, { "patternId" : "Drupal_Commenting_PostStatementComment", "level" : "Info", @@ -2098,6 +2106,10 @@ "patternId" : "SlevomatCodingStandard_Classes_SuperfluousAbstractClassNaming", "level" : "Info", "category" : "CodeStyle" + }, { + "patternId" : "SlevomatCodingStandard_Classes_SuperfluousErrorNaming", + "level" : "Info", + "category" : "CodeStyle" }, { "patternId" : "SlevomatCodingStandard_Classes_SuperfluousExceptionNaming", "level" : "Info", @@ -2142,6 +2154,10 @@ "patternId" : "SlevomatCodingStandard_Classes_UselessLateStaticBinding", "level" : "Info", "category" : "CodeStyle" + }, { + "patternId" : "SlevomatCodingStandard_Commenting_DeprecatedAnnotationDeclaration", + "level" : "Info", + "category" : "CodeStyle" }, { "patternId" : "SlevomatCodingStandard_Commenting_DisallowCommentAfterCode", "level" : "Info", @@ -2189,6 +2205,9 @@ "parameters" : [ { "name" : "allowDocCommentAboveReturn", "default" : false + }, { + "name" : "allowAboveNonAssignment", + "default" : false } ] }, { "patternId" : "SlevomatCodingStandard_Commenting_RequireOneLineDocComment", @@ -2306,6 +2325,20 @@ "patternId" : "SlevomatCodingStandard_ControlStructures_NewWithoutParentheses", "level" : "Info", "category" : "CodeStyle" + }, { + "patternId" : "SlevomatCodingStandard_ControlStructures_RequireMultiLineCondition", + "level" : "Info", + "category" : "CodeStyle", + "parameters" : [ { + "name" : "minLineLength", + "default" : 121 + }, { + "name" : "booleanOperatorOnPreviousLine", + "default" : false + }, { + "name" : "alwaysSplitAllConditionParts", + "default" : false + } ] }, { "patternId" : "SlevomatCodingStandard_ControlStructures_RequireMultiLineTernaryOperator", "level" : "Info", @@ -2330,6 +2363,17 @@ "patternId" : "SlevomatCodingStandard_ControlStructures_RequireShortTernaryOperator", "level" : "Info", "category" : "CodeStyle" + }, { + "patternId" : "SlevomatCodingStandard_ControlStructures_RequireSingleLineCondition", + "level" : "Info", + "category" : "CodeStyle", + "parameters" : [ { + "name" : "maxLineLength", + "default" : 120 + }, { + "name" : "alwaysForSimpleConditions", + "default" : true + } ] }, { "patternId" : "SlevomatCodingStandard_ControlStructures_RequireTernaryOperator", "level" : "Info", @@ -2424,6 +2468,25 @@ "name" : "enable", "default" : null } ] + }, { + "patternId" : "SlevomatCodingStandard_Functions_RequireMultiLineCall", + "level" : "Info", + "category" : "CodeStyle", + "parameters" : [ { + "name" : "minLineLength", + "default" : 121 + } ] + }, { + "patternId" : "SlevomatCodingStandard_Functions_RequireSingleLineCall", + "level" : "Info", + "category" : "CodeStyle", + "parameters" : [ { + "name" : "maxLineLength", + "default" : 120 + }, { + "name" : "ignoreWithComplexParameter", + "default" : true + } ] }, { "patternId" : "SlevomatCodingStandard_Functions_StaticClosure", "level" : "Info", @@ -2807,6 +2870,9 @@ }, { "name" : "ignoreSpacesInComment", "default" : false + }, { + "name" : "ignoreSpacesInParameters", + "default" : false } ] }, { "patternId" : "Squiz_Arrays_ArrayBracketSpacing", @@ -3572,14 +3638,7 @@ }, { "patternId" : "WordPressVIPMinimum_Variables_VariableAnalysis", "level" : "Info", - "category" : "CodeStyle", - "parameters" : [ { - "name" : "allowUnusedCaughtExceptions", - "default" : false - }, { - "name" : "allowUnusedFunctionParameters", - "default" : true - } ] + "category" : "CodeStyle" }, { "patternId" : "WordPress_Arrays_ArrayDeclarationSpacing", "level" : "Info",