Commit 2be483c
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
1 file changed
+6
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
205 | 211 | | |
0 commit comments