Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class naming convention check does not strictly check for Camel_Caps #2258

Open
1 task done
jrfnl opened this issue Jun 19, 2023 · 0 comments
Open
1 task done

Class naming convention check does not strictly check for Camel_Caps #2258

jrfnl opened this issue Jun 19, 2023 · 0 comments

Comments

@jrfnl
Copy link
Member

jrfnl commented Jun 19, 2023

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?

  • I have verified the issue still exists in the develop branch of WPCS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant