Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 16, 2025

Description

Composer: update to PHPCSExtra 1.5.0

PHPCSExtra 1.5.0 has been released and offers 7 new sniffs, some of which we may want to use.

Ref: https://github.com/PHPCSStandards/PHPCSExtra/releases/tag/1.5.0

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.

Suggested changelog entry

Added:

  • WordPress-Extra: the following additional sniffs have been added to the ruleset: Universal.Attributes.BracketSpacing and Universal.Attributes.DisallowAttributeParentheses.

Changed:

  • The minimum required PHPCSExtra version to 1.5.0 (was 1.4.0).

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.
@GaryJones GaryJones merged commit 262b65a into develop Nov 16, 2025
40 checks passed
@GaryJones GaryJones deleted the feature/updates-for-phpcsextra-1.5.0 branch November 16, 2025 17:19
@jrfnl jrfnl mentioned this pull request Nov 24, 2025
41 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants