diff --git a/Alley-Interactive/ruleset.xml b/Alley-Interactive/ruleset.xml index db37ae4..e41c281 100644 --- a/Alley-Interactive/ruleset.xml +++ b/Alley-Interactive/ruleset.xml @@ -20,6 +20,8 @@ + + @@ -95,4 +97,17 @@ tests/*Test.php + + + + + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index cce5d4b..ac73a04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ This project adheres to [Keep a CHANGELOG](https://keepachangelog.com/en/1.0.0/) ### Unreleased - Allow PSR-4 style `ClassName.php` file names to support our migration to PSR-4 for test files. +- Remove the `PEAR.Functions.FunctionCallSignature` sniff from the ruleset and + replace it with `PSR2.Methods.FunctionCallSignature`. This change is to allow + for multi-line function calls to be formatted in a more readable way without having to insert a new line before the first argument. ### 2.0.2 diff --git a/README.md b/README.md index 57294d8..fd14770 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ You can also pass arguments to the composer phpcs script, following a `--` opera composer run phpcs -- --report=summary ``` -### Extending the ruleset +### Extending the Ruleset You can create a custom ruleset for your project that extends or customizes these rules by creating your own `phpcs.xml` file in your project, which @@ -68,6 +68,16 @@ references these rules, like this: ``` +## Testing + +When contributing to this project, modifications to the ruleset should have a +corresponding test in the `tests` directory. For the most part, this takes the +form of a passing test in `tests/fixtures/pass` and a failing one in +`tests/fixtures/fail`. You can run the tests with `composer phpunit`. If you +want to run PHPCS against the test fixtures, you can run +`composer phpcs:fixtures` to ensure that what is passing/failing matches your +expectations. + ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. diff --git a/composer.json b/composer.json index f4d52a8..be8eb8e 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,8 @@ }, "scripts": { "phpcbf": "phpcbf --standard=Alley-Interactive tests/*Test.php", - "phpcs": "phpcs --standard=Alley-Interactive tests/*Test.php -vsn", - "phpcs:fixtures": "phpcs --standard=Alley-Interactive tests/fixtures", + "phpcs": "phpcs --standard=Alley-Interactive tests/*Test.php -sn", + "phpcs:fixtures": "phpcs -sn --standard=Alley-Interactive tests/fixtures", "phpunit": "phpunit", "test": [ "@phpcs", diff --git a/tests/PhpcsHelper.php b/tests/PhpcsHelper.php index a04ab7a..6c6721b 100644 --- a/tests/PhpcsHelper.php +++ b/tests/PhpcsHelper.php @@ -26,7 +26,7 @@ protected function run_phpcs( string $file ): array { $base_path = dirname( __DIR__ ); $shell = sprintf( - '%s %s %s --standard=%s --no-cache --report=json', + '%s %s "%s" --standard=%s --no-cache --report=json', PHP_BINARY, "{$base_path}/vendor/bin/phpcs", $file, diff --git a/tests/fixtures/fail/functions-empty-arguments.php b/tests/fixtures/fail/functions-empty-arguments.php new file mode 100644 index 0000000..a1ea312 --- /dev/null +++ b/tests/fixtures/fail/functions-empty-arguments.php @@ -0,0 +1,8 @@ + 'bar', +]); diff --git a/tests/fixtures/pass/functions.php b/tests/fixtures/pass/functions.php index dec2e87..5805fd8 100644 --- a/tests/fixtures/pass/functions.php +++ b/tests/fixtures/pass/functions.php @@ -10,3 +10,18 @@ }; echo esc_html( $ai_function() ); + +// Allow function arguments on the same line as the function call. +// Supports PSR2.Methods.FunctionCallSignature. +ai_method_call( [ + 'foo' => 'bar', +] ); + +ai_method_call( + [ + 'foo' => 'bar', + ] +); + +ai_method_call( [ 'foo' => 'bar' ] ); +ai_method_call();