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

Sniff to enforce naming conventions for class/function/const aliases #232

Open
jrfnl opened this issue Jun 13, 2023 · 0 comments
Open

Sniff to enforce naming conventions for class/function/const aliases #232

jrfnl opened this issue Jun 13, 2023 · 0 comments

Comments

@jrfnl
Copy link
Member

jrfnl commented Jun 13, 2023

Is your feature request related to a problem?

It would be nice to have a sniff which could check that an alias name provided in import use statements and trait use statements complies with certain naming conventions.

The most common naming convention for class names would probably be StudlyCaps/PascalCase.
Along the same lines, the most common naming convention for function names would probably be camelCase, while for constants it would be MACRO_CASE.

Supporting other naming conventions for each should also be considered.

Describe the solution you'd like

A new sniff with a choice of which naming convention to enforce for each type of alias.

Some examples:

// StudlyCaps/PascalCase class aliases.
use Vendor\Package\ClassName as MyClass; // OK.
use Vendor\Package\ClassName as myClass; // Not OK.
use Vendor\Package\ClassName as My_Class; // Not OK.

// camelCase function aliases.
use function Vendor\Package\functionName as myFunction; // OK.
use function Vendor\Package\functionName as my_function; // Not OK.

class Aliased_Talker {
    use A, B {
        B::bigTalk as talk; // OK
        B::smallTalk as TALKING; // Not OK.
    }
}

// MACRO_CASE constant aliases,
use const Vendor\Package\CONSTANT_NAME as MY_CONSTANT; // OK.
use const Vendor\Package\CONSTANT_NAME as myCONSTANT; // Not OK.

Additional context (optional)

Might be a good idea for the sniff to also check that aliases also complies with the following additional conventions:

  • No leading underscore(s).
  • No trailing underscore(s).
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