si6/pre-commit-hook

0.1.3 2019-09-13 16:06 UTC

This package is auto-updated.

Last update: 2021-09-06 19:50:40 UTC


README

关于

自动安装的 git pre-commit 钩子,用于运行 PHP Code Sniffer 代码检查,以符合 PSR2 编码标准。它仅检查要提交的文件。

灵感来源于 使用 composer、git 钩子和 phpcs 约束代码标准https://github.com/smgladkovskiy/phpcs-git-pre-commit 以及 https://gist.github.com/BrizzleRocker/62ed61b37acf05344d4bce894e719251 。安装程序检查托管机上的操作系统并安装适用于平台的所需钩子。

安装

使用 composer require 命令安装 si6/pre-commit-hook

composer require "si6/pre-commit-hook"

或者,在您的 composer.json 文件中手动包含 si6/pre-commit-hook 的依赖关系

{
    "require-dev": {
        "si6/pre-commit-hook": "*"
    }
}

为了启用代码嗅探,将 post-install-cmdpost-update-cmd 添加到 composer.json 安装脚本中

"scripts": {
    "post-install-cmd": [
        "Si6\\PreCommitHook\\Installer::postInstall"
    ],
    "post-update-cmd": [
        "Si6\\PreCommitHook\\Installer::postInstall"
    ]
}

然后运行 composer installcomposer update。如果已存在,则会安装或更新 pre-commit 钩子。

使用方法

运行 git commit,预提交钩子将检查您提交的文件,就像您运行了

php phpcs.phar --standard=rule.xml --colors --encoding=utf-8 -n -p /path/to/file.php