diff-sniffer / git
This package is abandoned and no longer maintained.
The author suggests using the diff-sniffer/diff-sniffer package instead.
Diff Sniffer, a tool to validate coding standards only in changed line
0.5.1
2020-10-02 00:18 UTC
Requires
- php: ^7.3 || ^8.0
- ext-json: *
- jean85/pretty-package-versions: ^1.5
- morozov/bootstrap: ^1.1
- squizlabs/php_codesniffer: ^3.5
Requires (Dev)
- doctrine/coding-standard: ^8.1
- php-vfs/php-vfs: ^1.4.1
- phpstan/phpstan: ^0.12
- phpstan/phpstan-phpunit: ^0.12
- phpunit/phpunit: ^9.3.1
This package is auto-updated.
Last update: 2023-03-09 08:58:33 UTC
README
This tool allows you to use PHP_CodeSniffer as a pre-commit hook. The main difference from existing solutions that this one validates only changed lines of code but not the whole source tree.
Installation
Download a PHAR package of the latest release and put it somewhere within your $PATH
:
$ wget https://github.com/diff-sniffer/diff-sniffer/releases/latest/download/diff-sniffer.phar
$ chmod +x diff-sniffer.phar
$ sudo cp diff-sniffer.phar /usr/local/bin/diff-sniffer
Create a pre-commit hook in a specific Git repository .
$ cd /path/to/repo
$ cat > .git/hooks/pre-commit << 'EOF'
#!/usr/bin/env bash
diff-sniffer --staged "$@"
EOF
Alternatively, you can create a global pre-commit hook for your user (see man githooks
):
$ cat > ~/.config/git/hooks/pre-commit << 'EOF'
#!/usr/bin/env bash
diff-sniffer --staged "$@"
EOF
You can also install Diff Sniffer manually:
$ git clone git@github.com:diff-sniffer/diff-sniffer.git
$ cd diff-sniffer
$ composer install
$ bin/diff-sniffer --version
Continuous integration mode
Diff Sniffer can also run on a CI server and validate pull requests. For example, on Travis CI:
$ wget https://github.com/diff-sniffer/diff-sniffer/releases/latest/download/diff-sniffer.phar
$ php diff-sniffer.phar origin/$TRAVIS_BRANCH...$TRAVIS_PULL_REQUEST_SHA