Skip to content

Commit 2be483c

Browse files
committed
WordPress-Extra: add some sniffs related to attribute formatting
It's common for code to contain PHP 8.0 attributes, even if the code still needs to run on PHP < 8.0 as attributes are cross-version compatible in the sense that they won't cause parse errors on older PHP versions but will be seen as a comment. WordPress Core at this moment contains 193 attributes in 156 files. https://github.com/search?q=repo%3AWordPress%2Fwordpress-develop+%23%5B&type=code With this in mind, it makes sense to start adding some rules related to attributes formatting to WordPress-Extra. These rules should eventually be moved to WordPress-Core after a Make post. PHPCSExtra is starting to add some sniffs for attribute formatting. Though the set is nowhere near complete yet, these initial two sniffs should make a good addition for WPCS. * The `Universal.Attributes.BracketSpacing` demands no spacing on the inside of attribute brackets. While this may seem inconsistent with the otherwise space-richness of WordPressCS, if we look at prior art in WordPress Core, all attributes currently in WordPress Core comply with the "no spacing inside of the brackets" rule. This means that if/when the rule would move to the WordPress-Core ruleset, no code churn is expected as no fixes will be needed. * The `Universal.Attributes.DisallowAttributeParentheses` demands that attribute instantiations only have parentheses when parameters are passed. Again, this is 100% in line with prior art in WordPress Core. As a side-note: both the above rules are also in line with PERCS, which means that they don't raise the barrier to entry for new contributors to WordPress.
1 parent 08c3d1b commit 2be483c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

WordPress-Extra/ruleset.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,10 @@
202202
<!-- Check for single blank line after namespace declaration. -->
203203
<rule ref="PSR2.Namespaces.NamespaceDeclaration"/>
204204

205+
<!-- Do not allow spacing inside the brackets for attributes. -->
206+
<rule ref="Universal.Attributes.BracketSpacing"/>
207+
208+
<!-- Forbid parentheses for attribute instantiations without parameters. -->
209+
<rule ref="Universal.Attributes.DisallowAttributeParentheses"/>
210+
205211
</ruleset>

0 commit comments

Comments
 (0)