PHPCSExtra icon indicating copy to clipboard operation
PHPCSExtra copied to clipboard

Sniff to enforce naming conventions for namespace names

Open jrfnl opened this issue 1 year ago • 0 comments

Is your feature request related to a problem?

It would be nice to have a sniff which could check that the name in a namespace declarations complies with certain naming conventions.

The most common naming convention would probably be StudlyCaps/PascalCase, but supporting other naming conventions should also be considered.

Describe the solution you'd like

A new sniff with a choice of which naming convention to enforce. The naming convention would need to be applied to each part of the namespace declaration.

Some examples:

// StudlyCaps/PascalCase.
namespace VendorName\PackageName\SubCategory\SubLevel; // OK.
namespace Vendor_Name\package_name\subCategory\sublevel; // Not OK.

// Camel_Caps with underscores.
namespace Vendor_Name\Package_Name\Sub_Category\Sub_Level; // OK.
namespace VendorName\package_name\subCategory\sublevel; // Not OK.

// snake_case.
namespace vendor_name\package_name\sub_category\sub_level; // OK.
namespace Vendor_Name\packageName\subCategory\Sublevel; // Not OK.

Additional context (optional)

Might be a good idea for the sniff to also check that each part of the name complies with the following additional conventions:

  • No leading underscore(s).
  • No trailing underscore(s).
namespace VendorName\PackageName\SubCategory\SubLevel; // OK.
namespace _VendorName\_PackageName__\SubLevel_; // Not OK.

jrfnl avatar Jun 12 '23 21:06 jrfnl