Skip to content

Commit

Permalink
Merge pull request #2255 from WordPress/feature/core-add-oo-declarati…
Browse files Browse the repository at this point in the history
…on-check

Core: add new sniff to check formatting of OO declaration statement
  • Loading branch information
dingo-d authored Jun 20, 2023
2 parents cb90f01 + 619173b commit fa01dd7
Show file tree
Hide file tree
Showing 75 changed files with 12 additions and 74 deletions.
1 change: 0 additions & 1 deletion Tests/RulesetCheck/class-ruleset-test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,4 @@ class Ruleset_Test {
end:
echo 'This is a goto - it needs to be here to prevent parse errors';
}

}
12 changes: 12 additions & 0 deletions WordPress-Core/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,18 @@
<!-- Class opening braces should be on the same line as the statement. -->
<rule ref="Generic.Classes.OpeningBraceSameLine"/>

<!-- Implied via examples: one space after keywords in class declaration, class declaration on one line,
close brace on line by itself and no blank lines between OO structure body and close brace. -->
<rule ref="PSR2.Classes.ClassDeclaration"/>
<rule ref="PSR2.Classes.ClassDeclaration.OpenBraceNewLine">
<!-- WP expects open brace on same line as class keyword. -->
<severity>0</severity>
</rule>
<rule ref="PSR2.Classes.ClassDeclaration.OpenBraceWrongLine">
<!-- WP expects open brace on same line as class keyword. -->
<severity>0</severity>
</rule>

<!-- References to self in a class should be lower-case and not have extraneous spaces,
per implicit conventions in the core codebase; the NotUsed code refers to using the
fully-qualified class name instead of self, for which there are instances in core. -->
Expand Down
1 change: 0 additions & 1 deletion WordPress/AbstractArrayAssignmentRestrictionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,4 @@ public function process_token( $stackPtr ) {
* with custom error message passed to ->process().
*/
abstract public function callback( $key, $val, $line, $group );

}
1 change: 0 additions & 1 deletion WordPress/AbstractFunctionRestrictionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,5 +356,4 @@ protected function prepare_name_for_regex( $function_name ) {

return $function_name;
}

}
1 change: 0 additions & 1 deletion WordPress/Helpers/IsUnitTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,4 @@ protected function is_test_class( File $phpcsFile, $stackPtr ) {

return false;
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,5 +466,4 @@ protected function process_multi_line_array( $stackPtr, $opener, $closer ) {
$end_of_last_item = $end_of_this_item;
}
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/Arrays/ArrayIndentationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,5 +545,4 @@ protected function fix_alignment_error( $ptr, $new_indent ) {
$this->phpcsFile->fixer->replaceToken( ( $ptr - 1 ), $new_indent );
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,4 @@ public function process_token( $stackPtr ) {
}
}
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,4 @@ public function process_token( $stackPtr ) {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -580,5 +580,4 @@ protected function validate_align_multiline_items() {
// Reset to the default if an invalid value was received.
$this->alignMultilineItems = 'always';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,4 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
$data
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/DB/DirectDatabaseQuerySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,5 +297,4 @@ protected function mergeFunctionLists() {
$this->addedCustomFunctions['cachedelete'] = $this->customCacheDeleteFunctions;
}
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,5 +654,4 @@ protected function analyse_implode( $implode_token ) {

return (bool) preg_match( '`^(["\'])%[dfFs]\1$`', $array_fill_params[3]['raw'] );
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/DB/PreparedSQLSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,4 @@ function ( $symbol ) {

return $this->end;
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/DB/RestrictedClassesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ public function getGroups() {

);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/DB/RestrictedFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ public function getGroups() {
),
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/DB/SlowDBQuerySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@ public function getGroups() {
public function callback( $key, $val, $line, $group ) {
return true;
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/DateTime/RestrictedFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@ public function getGroups() {
),
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/PHP/DevelopmentFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ public function getGroups() {
),
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/PHP/DiscouragedPHPFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@ public function getGroups() {
),
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/PHP/DontExtractSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ public function getGroups() {

);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/PHP/POSIXFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ public function getGroups() {

);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/PHP/RestrictedPHPFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ public function getGroups() {
),
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/PHP/TypeCastsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,4 @@ public function process_token( $stackPtr ) {
break;
}
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/PHP/YodaConditionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,4 @@ public function process_token( $stackPtr ) {

$this->phpcsFile->addError( 'Use Yoda Condition checks, you must.', $stackPtr, 'NotYoda' );
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/Security/NonceVerificationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,4 @@ protected function mergeFunctionLists() {
$this->addedCustomFunctions['unslashsanitize'] = $this->customUnslashingSanitizingFunctions;
}
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/Security/PluginMenuSlugSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,4 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
}
}
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/Security/SafeRedirectSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ public function getGroups() {
),
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,4 @@ protected function mergeFunctionLists() {
$this->addedCustomFunctions['unslashsanitize'] = $this->customUnslashingSanitizingFunctions;
}
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/WP/CapabilitiesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,5 +477,4 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
)
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/WP/CapitalPDangitSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,4 @@ protected function retrieve_misspellings( $match_stack ) {

return $misspelled;
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/WP/CronIntervalSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,4 @@ public function confused( $stackPtr ) {
'ChangeDetected'
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/WP/DeprecatedClassesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,4 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content
$data
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/WP/DeprecatedFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -1550,5 +1550,4 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content
$data
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/WP/DeprecatedParameterValuesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,4 @@ protected function process_parameter( $matched_content, $parameter, $parameter_a
$data
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/WP/DiscouragedConstantsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,4 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
);
}
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/WP/DiscouragedFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ public function getGroups() {
),
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/WP/GlobalVariablesOverrideSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,5 +435,4 @@ protected function add_error( $stackPtr, $data = array() ) {
$data
);
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/WP/PostsPerPageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ public function callback( $key, $val, $line, $group ) {

return false;
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/WhiteSpace/CastStructureSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@ public function process_token( $stackPtr ) {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -575,5 +575,4 @@ public function process_token( $stackPtr ) {
}
}
}

}
1 change: 0 additions & 1 deletion WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ public function register() {

return $tokens;
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/Arrays/ArrayDeclarationSpacingUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,4 @@ public function getErrorList( $testFile = '' ) {
public function getWarningList() {
return array();
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/Arrays/ArrayIndentationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,4 @@ public function getErrorList() {
public function getWarningList() {
return array();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ public function getErrorList() {
public function getWarningList() {
return array();
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/Arrays/CommaAfterArrayItemUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,4 @@ public function getErrorList() {
public function getWarningList() {
return array();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,4 @@ public function getWarningList() {
570 => 1,
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ public function getWarningList() {
8 => 1,
);
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,4 @@ public function getWarningList() {
177 => 1,
);
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/DB/RestrictedClassesUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,4 @@ public function getErrorList( $testFile = '' ) {
public function getWarningList() {
return array();
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/DB/RestrictedFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,4 @@ public function getErrorList() {
public function getWarningList() {
return array();
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/DB/SlowDBQueryUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ public function getWarningList() {
19 => 2,
);
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,4 @@ public function getErrorList() {
public function getWarningList() {
return array();
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/Files/FileNameUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,4 @@ public function getErrorList( $testFile = '' ) {
public function getWarningList() {
return array();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,4 @@ public function getWarningList( $testFile = 'PrefixAllGlobalsUnitTest.1.inc' ) {
return array();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,4 @@ public function getErrorList() {
public function getWarningList() {
return array();
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ public function getWarningList() {
34 => 1,
);
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,4 @@ public function getWarningList() {
39 => 1,
);
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/PHP/DontExtractUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ public function getErrorList() {
public function getWarningList() {
return array();
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/PHP/POSIXFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ public function getErrorList() {
public function getWarningList() {
return array();
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ public function getErrorList() {
public function getWarningList() {
return array();
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/PHP/YodaConditionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,4 @@ public function getErrorList() {
public function getWarningList() {
return array();
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/Security/EscapeOutputUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,4 @@ public function getErrorList() {
public function getWarningList() {
return array();
}

}
1 change: 0 additions & 1 deletion WordPress/Tests/Security/SafeRedirectUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ public function getWarningList() {
3 => 1,
);
}

}
Loading

0 comments on commit fa01dd7

Please sign in to comment.