arispati / phpcs-pre-commit
在git提交前运行phpcs
v1.2.0
2024-06-12 10:05 UTC
Requires
- php: ^8.2|^8.3
- illuminate/console: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- squizlabs/php_codesniffer: ^3.10
README
在git提交前运行phpcs
目录
要求
- PHP >= ^8.2 | ^8.3
- Laravel >= ^10.0 | ^11.0
安装
- 将此命令添加到composer.json中的脚本部分,在
post-install-cmd
和post-update-cmd
属性中
@php artisan arispati:phpcs-install
// composer.json { ... "scripts": { "post-install-cmd": [ "@php artisan arispati:phpcs-install" ], "post-update-cmd": [ "@php artisan arispati:phpcs-install" ], }, ... }
- 然后使用composer安装此包
composer require --dev arispati/phpcs-pre-commit
- 现在当你提交更改并出现错误时,它看起来像这样
[PRE-COMMIT] Running PHP_CodeSniffer using the PSR12 standard E 1 / 1 (100%) FILE: ...~/HomeController.php -------------------------------------------------------------------------------- FOUND 5 ERRORS AFFECTING 4 LINES -------------------------------------------------------------------------------- 11 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 4 11 | ERROR | [x] Expected 1 space after closing parenthesis; found newline 12 | ERROR | [x] Line indented incorrectly; expected at least 8 spaces, found 4 13 | ERROR | [x] Line indented incorrectly; expected at least 12 spaces, found 8 14 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 4 -------------------------------------------------------------------------------- PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY -------------------------------------------------------------------------------- Time: 138ms; Memory: 10MB [PRE-COMMIT] Please fix all of the violations or commit with the --no-verify option
卸载
- 运行此命令以移除git钩子脚本
php artisan arispati:phpcs-uninstall
- 从
post-install-cmd
和post-update-cmd
属性中移除composer脚本@php artisan arispati:phpcs-install
- 然后使用composer移除此包
composer remove --dev arispati/phpcs-pre-commit