Skip to content

New Universal.WhiteSpace.BackedEnumColonSpacing sniff#453

Open
rodrigoprimo wants to merge 1 commit into
PHPCSStandards:developfrom
rodrigoprimo:enum-colon-spacing
Open

New Universal.WhiteSpace.BackedEnumColonSpacing sniff#453
rodrigoprimo wants to merge 1 commit into
PHPCSStandards:developfrom
rodrigoprimo:enum-colon-spacing

Conversation

@rodrigoprimo

Copy link
Copy Markdown
Collaborator

This sniff checks the whitespace around the colon in a backed enum declaration.

The desired spacing before and after the colon is configurable via the spacingBefore (defaults to no space) and spacingAfter (defaults to a single space) properties.

The default values follow PER Coding Style 2.0, section 9: "When using a backed enum, there MUST NOT be a space between the enum name and colon, and there MUST be exactly one space between the colon and the backing type."

Non-backed enums are ignored.

Violations are reported under the SpacingBefore and SpacingAfter error codes and are auto-fixable in most cases.

In #443, I suggested EnumColonSpacing as the name of this sniff, but here I opted for BackedEnumColonSpacing to make it more explicit that this sniff only applies to backed enums.

Fixes #443.

Suggested changelog entry

  • New Universal.WhiteSpace.BackedEnumColonSpacing sniff to enforce consistent spacing around the colon in backed enum declarations.

…lon spacing

Add the `Universal.WhiteSpace.BackedEnumColonSpacing` sniff which enforces the
PER Coding Style 2.0 (section 9) spacing around the colon of a backed
enum declaration: no space between the enum name and the colon, and a
single space between the colon and the backing type.

The amount of spacing on either side is configurable via the
`spacingBefore` (default 0) and `spacingAfter` (default 1) properties.

Fixes 443.

Ref: https://github.com/php-fig/per-coding-style/blob/2.0.0/spec.md#9-enumerations
@rodrigoprimo

Copy link
Copy Markdown
Collaborator Author

Force-pushed without changes to re-trigger the GH Actions job that failed yesterday due to a temporary error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Backed enums: sniff to enforce spacing around the colon

1 participant