arispati/phpcs-pre-commit

在git提交前运行phpcs

v1.2.0 2024-06-12 10:05 UTC

This package is auto-updated.

Last update: 2024-09-12 10:53:59 UTC


README

在git提交前运行phpcs

目录

要求

  • PHP >= ^8.2 | ^8.3
  • Laravel >= ^10.0 | ^11.0

安装

  • 将此命令添加到composer.json中的脚本部分,在post-install-cmdpost-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-cmdpost-update-cmd属性中移除composer脚本@php artisan arispati:phpcs-install
  • 然后使用composer移除此包
composer remove --dev arispati/phpcs-pre-commit