Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 11, 2025

While the Universal.WhiteSpace.CommaSpacing sniff would previously already flag spacing around commas in PHP attributes, this commit adds some special handling for this.

This commit makes the following changes:

  1. Stop flagging "space before comma" when the comma is preceded by an attribute opener.
    This is a parse error, but more importantly, we want to avoid conflicts with "bracket spacing" sniffs, so leave the spacing after an attribute opener to a "bracket spacing" sniff (like the new Universal.Attributes.BracketSpacing sniff as introduced via PR ✨ New Universal.Attributes.BracketSpacing sniff #406).
  2. Stop flagging "space after comma" when the comma is followed by an attribute closer.
    Trailing commas are allowed in PHP attributes, but more importantly, we want to avoid conflicts with "bracket spacing" sniffs, so bow out.
  3. Differentiate the error code for commas found directly in an attribute block.
    This allows for more modularly including/excluding errors specific to comma spacing for commas in attribute blocks.
    Note: only commas between attributes in an attribute block will now use the InAttributeBlock suffix.
    Commas used to separate parameters passed to an attribute instantiation will still be flagged with the InFunctionCall suffix, same as before.

Includes tests.

Fixes #391

…attributes

While the `Universal.WhiteSpace.CommaSpacing` sniff would previously already flag spacing around commas in PHP attributes, this commit adds some special handling for this.

This commit makes the following changes:
1. Stop flagging "space before comma" when the comma is preceded by an attribute opener.
    This is a parse error, but more importantly, we want to avoid conflicts with "bracket spacing" sniffs, so leave the spacing after an attribute opener to a "bracket spacing" sniff (like the new `Universal.Attributes.BracketSpacing` sniff as introduced via PR 406).
2. Stop flagging "space after comma" when the comma is followed by an attribute closer.
    Trailing commas are allowed in PHP attributes, but more importantly, we want to avoid conflicts with "bracket spacing" sniffs, so bow out.
3. Differentiate the error code for commas found directly in an attribute block.
    This allows for more modularly including/excluding errors specific to comma spacing for commas in attribute blocks.
    Note: only commas between attributes in an attribute block will now use the `InAttributeBlock` suffix.
    Commas used to separate parameters passed to an attribute instantiation will still be flagged with the `InFunctionCall` suffix, same as before.

Includes tests.

Fixes 391
@jrfnl jrfnl added this to the 1.5.0 milestone Nov 11, 2025
@jrfnl jrfnl merged commit e13359f into develop Nov 11, 2025
79 checks passed
@jrfnl jrfnl deleted the feature/391-universal-commaspacing-update-for-commas-in-attributes branch November 11, 2025 19:06
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.

[FR] Attributes: sniff to enforce comma spacing

2 participants