-
-
Notifications
You must be signed in to change notification settings - Fork 0
Refactored case sniffs to allow choosing snake or camel case. #12
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
|
|
||
| --- | ||
| PHP_CodeSniffer standard enforcing: | ||
| - `snake_case` naming for local variables and function/method parameters | ||
| - Consistent naming conventions for local variables and function/method parameters (configurable: `snakeCase` or `camelCase`) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Configurable naming docs are clear; fix markdown fenced-block spacing for lint The new sections for You can fix all four places like this: -**With `snakeCase` (default):**
-```php
+**With `snakeCase` (default):**
+
+```php
@@
-**With `camelCase`:**
-```php
+**With `camelCase`:**
+
+```php
@@
-**With `snakeCase` (default):**
-```php
+**With `snakeCase` (default):**
+
+```php
@@
-**With `camelCase`:**
-```php
+**With `camelCase`:**
+
+```phpThis should clear the MD031 “Fenced code blocks should be surrounded by blank lines” findings while keeping the rendered output the same. Also applies to: 63-65, 73-91, 93-122, 130-155, 159-159 🤖 Prompt for AI Agents |
||
| - PHPUnit data provider naming conventions and organization | ||
|
|
||
| ## Installation | ||
|
|
@@ -60,8 +60,8 @@ Use individual sniffs: | |
| ```xml | ||
| <ruleset name="Custom Standards"> | ||
| <!-- Naming Conventions --> | ||
| <rule ref="DrevOps.NamingConventions.LocalVariableSnakeCase"/> | ||
| <rule ref="DrevOps.NamingConventions.ParameterSnakeCase"/> | ||
| <rule ref="DrevOps.NamingConventions.LocalVariableNaming"/> | ||
| <rule ref="DrevOps.NamingConventions.ParameterNaming"/> | ||
|
|
||
| <!-- Testing Practices --> | ||
| <rule ref="DrevOps.TestingPractices.DataProviderPrefix"/> | ||
|
|
@@ -70,55 +70,93 @@ Use individual sniffs: | |
| </ruleset> | ||
| ``` | ||
|
|
||
| ## `LocalVariableSnakeCase` | ||
| ### Configure naming convention | ||
|
|
||
| Enforces `snake_case` for local variables inside functions/methods. | ||
| By default, both sniffs enforce `snakeCase`. Configure to use `camelCase`: | ||
|
|
||
| ```xml | ||
| <ruleset name="Custom Standards"> | ||
| <rule ref="DrevOps.NamingConventions.LocalVariableNaming"> | ||
| <properties> | ||
| <property name="format" value="camelCase"/> | ||
| </properties> | ||
| </rule> | ||
|
|
||
| <rule ref="DrevOps.NamingConventions.ParameterNaming"> | ||
| <properties> | ||
| <property name="format" value="camelCase"/> | ||
| </properties> | ||
| </rule> | ||
| </ruleset> | ||
| ``` | ||
|
|
||
| ## `LocalVariableNaming` | ||
|
|
||
| Enforces consistent naming convention for local variables inside functions/methods. | ||
|
|
||
| **With `snakeCase` (default):** | ||
| ```php | ||
| function processOrder() { | ||
| $order_id = 1; // ✓ Valid | ||
| $orderId = 1; // ✗ Error: VariableNotSnakeCase | ||
| $orderId = 1; // ✗ Error: NotSnakeCase | ||
| } | ||
| ``` | ||
|
|
||
| **With `camelCase`:** | ||
| ```php | ||
| function processOrder() { | ||
| $orderId = 1; // ✓ Valid | ||
| $order_id = 1; // ✗ Error: NotCamelCase | ||
| } | ||
| ``` | ||
|
|
||
| Excludes: | ||
| - Function/method parameters (handled by `ParameterSnakeCase`) | ||
| - Function/method parameters (handled by `ParameterNaming`) | ||
| - Class properties (not enforced) | ||
| - Reserved variables (`$this`, `$_GET`, `$_POST`, etc.) | ||
|
|
||
| ### Error code | ||
| ### Error codes | ||
|
|
||
| `DrevOps.NamingConventions.LocalVariableSnakeCase.NotSnakeCase` | ||
| - `DrevOps.NamingConventions.LocalVariableNaming.NotSnakeCase` (when `format="snakeCase"`) | ||
| - `DrevOps.NamingConventions.LocalVariableNaming.NotCamelCase` (when `format="camelCase"`) | ||
|
|
||
| ### Ignore | ||
|
|
||
| ```php | ||
| // phpcs:ignore DrevOps.NamingConventions.LocalVariableSnakeCase.NotSnakeCase | ||
| // phpcs:ignore DrevOps.NamingConventions.LocalVariableNaming.NotSnakeCase | ||
| $myVariable = 'value'; | ||
| ``` | ||
|
|
||
| ## `ParameterSnakeCase` | ||
| ## `ParameterNaming` | ||
|
|
||
| Enforces `snake_case` for function/method parameters. | ||
| Enforces consistent naming convention for function/method parameters. | ||
|
|
||
| **With `snakeCase` (default):** | ||
| ```php | ||
| function processOrder($order_id, $user_data) { // ✓ Valid | ||
| function processOrder($orderId, $userData) { // ✗ Error: ParameterNotSnakeCase | ||
| function processOrder($orderId, $userData) { // ✗ Error: NotSnakeCase | ||
| ``` | ||
|
|
||
| **With `camelCase`:** | ||
| ```php | ||
| function processOrder($orderId, $userData) { // ✓ Valid | ||
| function processOrder($order_id, $user_data) { // ✗ Error: NotCamelCase | ||
| ``` | ||
|
|
||
| Excludes: | ||
| - Parameters inherited from interfaces/parent classes | ||
| - Parameters in interface/abstract method declarations | ||
| - Class properties (including promoted constructor properties) | ||
|
|
||
| ### Error code | ||
| ### Error codes | ||
|
|
||
| `DrevOps.NamingConventions.ParameterSnakeCase.NotSnakeCase` | ||
| - `DrevOps.NamingConventions.ParameterNaming.NotSnakeCase` (when `format="snakeCase"`) | ||
| - `DrevOps.NamingConventions.ParameterNaming.NotCamelCase` (when `format="camelCase"`) | ||
|
|
||
| ### Ignore | ||
|
|
||
| ```php | ||
| // phpcs:ignore DrevOps.NamingConventions.ParameterSnakeCase.NotSnakeCase | ||
| // phpcs:ignore DrevOps.NamingConventions.ParameterNaming.NotSnakeCase | ||
| function process($legacyParam) {} | ||
| ``` | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align documentation with configurable naming and updated test names
The overall description now reflects configurable naming (snakeCase or camelCase), but a few spots are still out of sync:
AbstractVariableSnakeCaseSniffTest.php; the base test file appears to have been renamed toAbstractVariableNamingSniffTest.php, so this example should be updated.LocalVariableNamingSniff.phpandParameterNamingSniff.phpare described as enforcing snake_case only; elsewhere in the doc you describe them as configurable. Consider rewording those bullets to “enforces configurable naming (snakeCase or camelCase)” for consistency.AbstractVariableSnakeCaseSniffTest.phpand describes only snake_case-focused tests, while the new tests also cover camelCase and error-code selection/integration for both sniffs.$format = 'camelCase'in the sniffs’ configuration.Updating these references will keep the guidance consistent with the new behavior and reduce confusion for contributors and tooling that relies on this file.
Also applies to: 90-93, 96-99, 181-195, 292-293
🤖 Prompt for AI Agents