nelson6e65 / code-sniffer-helpers
Helpers for PHP Code Sniffer
Fund package maintenance!
Patreon
paypal.me/n6e65
Installs: 10 457
Dependents: 2
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/nelson6e65/code-sniffer-helpers
Requires
- php: >=7.2
Requires (Dev)
- composer/composer: ^2.0
- phpstan/phpstan: ^1.11
- squizlabs/php_codesniffer: ^3.5
README
Helpers for PHP Code Sniffer.
Installation
composer require --dev nelson6e65/code-sniffer-helpers
Features
Composer scripts
phpcbf for lint-staged
A wrapper to fix your staged code (or argumented files/folders) using the PHP Code Sniffer auto-fixer.
There is a bug that does not allows you to use it directly as autofixer (squizlabs/PHP_CodeSniffer#1818). There is a workarround for using it as a composer script, but does not works for using it in a lint-staged pre-commit hook.
This helper is designed to be run with lint-staged, but you can also use it directly in your composer script.
Setup with lint-staged
Add the script to your composer.json:
{
"scripts": {
"cs:fix-filtered": ["NelsonMartell\\PhpCodeSniffer\\ComposerScripts::phpcbf"]
}
}
I used
"cs:fix-filtered"name, but you can use any script name you like.
Configure your Husky + lint-staged in your package.json
{
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.php": "composer cs:fix-filtered"
}
}
Example for Husky 4. Adapt it if you use Husky 5.
Usage
You can also run it directly with composer by using composer cs:fix-filtered {PATHS}. Example:
composer cs:fix-filtered src/ tests/ config/my-config-file.php
Note: Non exixtent files/directories are ignored.
Output
The output is inspired on pretty-quick output:
composer cs:fix-filtered config/ src/Example.php src/non-existent-file.php
License
Copyright (c) 2021 Nelson Martell
Read the LICENSE file for details.
