WordPress-Coding-Standards icon indicating copy to clipboard operation
WordPress-Coding-Standards copied to clipboard

Class naming convention check does not strictly check for Camel_Caps

Open jrfnl opened this issue 2 years ago • 0 comments

Bug Description

According to the handbook:

Class, trait, interface and enum names should use capitalized words separated by underscores. Any acronyms should be all upper case.

Ref: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions

However, the current sniff being used to check this convention - PEAR.NamingConventions.ValidClassName - allows for both PascalCase as well as Camel_Caps (the difference being in the underscore enforcement).

Minimal Code Snippet

The issue happens when running this command:

phpcs test.php --standard=WordPress

... over a file containing this code:

class CamelCapsC {}
trait snake_case {}
interface CamelCase {}
enum CamelEnum: int {}

I would expect all four lines to get an error for the names not being in Camel_Caps, however, only the snake_case name is being flagged with the following two errors:

ERROR | [ ] Trait name must begin with a capital letter (PEAR.NamingConventions.ValidClassName.StartWithCapital)
ERROR | [ ] Trait name is not valid; consider Snake_Case instead (PEAR.NamingConventions.ValidClassName.Invalid)

Environment

Question Answer
PHP version irrelevant
PHP_CodeSniffer version master + extras
WPCS version develop
WPCS install type git clone

Additional Context (optional)

I don't think this is an urgent issue, but I did feel it should be recorded that this behaviour is happening and should be looked into at some point in the future.

Tested Against develop branch?

  • [x] I have verified the issue still exists in the develop branch of WPCS.

jrfnl avatar Jun 19 '23 19:06 jrfnl