I am trying to build a pre-commit script in SVN, and I want to run PHP_CodeSniffer on the modified lines only (as opposed to the whole file). So far I have this script:
#!/bin/sh
REPOS="$1"
TXN="$2"
# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "[a-zA-Z0-9]" > /dev/null || exit 1
# Check for code validation before commiting the script using PHP_CodeSniffer
/tmp/pear/download/PHP_CodeSniffer-1.4.3/scripts/phpcs-svn-pre-commit "$REPOS" -t "$TXN" >&2 || exit 1
# All checks passed, so allow the commit.
exit 0
PHP Code Sniffer (PHPCS) is a package for syntax checking, available from PEAR. It can check code against defined rules covering anything from whitespace through doc comments to variable naming conventions and beyond.
In the Settings dialog, go to Editor > Inspections. From the inspections screen, expand the PHP | Quality tools node and enable “PHP CodeSniffer validation”. In the configuration pane that is now enabled, select “Custom” from the “Coding standard” dropdown, locate the ruleset configuration ( phpcs.
In 2017, since CodeSniffer 3.0.0 release, there is new --cache
option.
Or you can use EasyCodingStandard, that does this by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With