Skip to content

Commit

Permalink
fix: Fix multiple test after vipwpcs update
Browse files Browse the repository at this point in the history
Unused variable was deprecated on this version Automattic/VIP-Coding-Standards#450
Note: users that have this pattern enabled will see a deprecation notice
  • Loading branch information
Francisco committed Sep 9, 2020
1 parent 22ae5cc commit 804f916
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Checks non-namespaced classes are referenced by FQN, not imported.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Checks for the correct usage of inline variable type declarations.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# SlevomatCodingStandard_Arrays_MultiLineArrayEndBracketPlacement

Enforces reasonable end bracket placement for multiline arrays.
Enforces reasonable end bracket placement for multi-line arrays.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SlevomatCodingStandard_Classes_SuperfluousErrorNaming

Reports use of superfluous suffix "Error" for errors.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Commenting: Deprecated Annotation Declaration
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
71 changes: 62 additions & 9 deletions src/main/resources/docs/description/description.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -2058,6 +2072,9 @@
"parameters" : [ {
"name" : "allowDocCommentAboveReturn",
"description" : "allowDocCommentAboveReturn"
}, {
"name" : "allowAboveNonAssignment",
"description" : "allowAboveNonAssignment"
} ]
}, {
"patternId" : "SlevomatCodingStandard_Commenting_RequireOneLineDocComment",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -2584,6 +2641,9 @@
}, {
"name" : "ignoreSpacesInComment",
"description" : "ignoreSpacesInComment"
}, {
"name" : "ignoreSpacesInParameters",
"description" : "ignoreSpacesInParameters"
} ]
}, {
"patternId" : "Squiz_Arrays_ArrayBracketSpacing",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<checkstyle version="4.3">
<file name="User.php">
<error source="WordPressVIPMinimum_Variables_VariableAnalysis" line="9" message="Unused variable `$notUsed`." severity="info" />
<error source="WordPressVIPMinimum_Security_StaticStrreplace" line="11" message="This code pattern is often used to run a very dangerous shell programs on your server. The code in these files needs to be reviewed, and possibly cleaned." severity="error" />
</file>
</checkstyle>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
<rule ref="WordPressVIPMinimum.Security.StaticStrreplace">
<type>error</type>
</rule>

<rule ref="WordPressVIPMinimum.Variables.VariableAnalysis"></rule>
</ruleset>
75 changes: 67 additions & 8 deletions src/main/resources/docs/patterns.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -2189,6 +2205,9 @@
"parameters" : [ {
"name" : "allowDocCommentAboveReturn",
"default" : false
}, {
"name" : "allowAboveNonAssignment",
"default" : false
} ]
}, {
"patternId" : "SlevomatCodingStandard_Commenting_RequireOneLineDocComment",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -2807,6 +2870,9 @@
}, {
"name" : "ignoreSpacesInComment",
"default" : false
}, {
"name" : "ignoreSpacesInParameters",
"default" : false
} ]
}, {
"patternId" : "Squiz_Arrays_ArrayBracketSpacing",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 804f916

Please sign in to comment.