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

Core: add initial sniffs for modifier keyword ordering rules #2102

Merged
merged 2 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions WordPress-Core/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,40 @@
<!-- Covered by the PSR2.Classes.PropertyDeclaration sniff. -->


<!--
#############################################################################
Handbook: Object-Oriented Programming - Visibility and modifier order.
Ref: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#visibility-and-modifier-order
#############################################################################
-->
<!-- Rule: When using multiple modifiers for a class declaration, the order should be as follows:
- First the optional abstract or final modifier.
- Next, the optional readonly modifier. -->

<!-- Rule: When using multiple modifiers for a constant declaration inside object-oriented structures,
the order should be as follows:
- First the optional final modifier.
- Next, the visibility modifier. -->

<!-- Covers rule: When using multiple modifiers for a property declaration, the order should be as follows:
- First a visibility modifier.
- Next, the optional static or readonly modifier (these keywords are mutually exclusive).
- Finally, the optional type declaration. -->
<!-- Covered by the PSR2.Classes.PropertyDeclaration sniff. -->

<!-- Covers rule: When using multiple modifiers for a method declaration, the order should be as follows:
- First the optional abstract or final modifier.
- Then, a visibility modifier.
- Finally, the optional static modifier. -->
<rule ref="PSR2.Methods.MethodDeclaration"/>
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<severity>0</severity>
</rule>

<!-- Implied through the examples: Single space after each modifier keyword. -->
<rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/>


<!--
#############################################################################
Handbook: Control Structures - Use elseif, not else if.
Expand Down
8 changes: 3 additions & 5 deletions WordPress-Extra/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed"/>
</rule>

<!-- Verify modifier keywords for declared methods and properties in classes.
https://github.com/WordPress/WordPress-Coding-Standards/issues/1101 -->
<rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/>
<rule ref="PSR2.Methods.MethodDeclaration"/>

<!-- Do not allow leading underscores in property or method names. Visibility should be used instead.
https://github.com/WordPress/WordPress-Coding-Standards/issues/1101 -->
<rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
<severity>5</severity>
</rule>
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<severity>5</severity>
</rule>

<!-- Do not allow multi-property declarations.
https://github.com/WordPress/WordPress-Coding-Standards/issues/1101 -->
Expand Down