Skip to content

New Universal.NamingConventions.EnumCaseName sniff#452

Open
rodrigoprimo wants to merge 1 commit into
PHPCSStandards:developfrom
rodrigoprimo:enum-case-name
Open

New Universal.NamingConventions.EnumCaseName sniff#452
rodrigoprimo wants to merge 1 commit into
PHPCSStandards:developfrom
rodrigoprimo:enum-case-name

Conversation

@rodrigoprimo

Copy link
Copy Markdown
Collaborator

This sniff verifies that enum case names are declared using PascalCase, as required by PER Coding Style 2.0 ("Enum case declarations MUST use PascalCase capitalization").

PascalCase is interpreted strictly: a name must start with an uppercase letter and must not contain two consecutive uppercase letters. This means acronyms and initialisms must be treated as regular words, so JsonValue is accepted while JSONValue is not. I'm assuming this is the correct interpretation of the PER rule, but I'm not sure.

Known limitations

The sniff relies on PHP_CodeSniffer\Util\Common::isCamelCaps(), which only recognizes ASCII letters. As a result, enum case names containing non-ASCII characters (for example case Café;) are flagged as not being in PascalCase, but I believe they should. This is a pre-existing limitation of isCamelCaps() that is shared by all the naming-convention sniffs that depend on it. I searched, and I believe this was not reported before. I can open an issue in the PHPCS repository about it if you agree that isCamelCaps() should be updated to support non-ASCII letters.

Fixes #444.

Suggested changelog entry

  • New Universal.NamingConventions.EnumCaseName sniff to verify that enum case names are declared using PascalCase.

Add the `Universal.NamingConventions.EnumCaseName` sniff which verifies that
enum case names are declared using PascalCase, as required by PER Coding Style
2.0, section 9.

The sniff registers `T_ENUM_CASE` and checks the following case name with
`Common::isCamelCaps()` in strict class-format mode, so a name must start with
an uppercase letter and must not contain consecutive uppercase letters.

Fixes 444
@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] Enum cases: sniff to enforce PascalCase capitalization

1 participant