New Universal.NamingConventions.EnumCaseName sniff#452
Open
rodrigoprimo wants to merge 1 commit into
Open
Conversation
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
17c2e7d to
cce2dde
Compare
Collaborator
Author
|
Force-pushed without changes to re-trigger the GH Actions job that failed yesterday due to a temporary error. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
JsonValueis accepted whileJSONValueis 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 examplecase Café;) are flagged as not being in PascalCase, but I believe they should. This is a pre-existing limitation ofisCamelCaps()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 thatisCamelCaps()should be updated to support non-ASCII letters.Fixes #444.
Suggested changelog entry
Universal.NamingConventions.EnumCaseNamesniff to verify that enum case names are declared using PascalCase.