Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use PHP_CodeSniffer for modified lines only

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
like image 375
Antonio Avatar asked Jan 01 '13 21:01

Antonio


People also ask

What is PHP Code sniffer?

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.

How do I run PHP CodeSniffer?

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.


1 Answers

In 2017, since CodeSniffer 3.0.0 release, there is new --cache option.

Or you can use EasyCodingStandard, that does this by default.

like image 178
Tomas Votruba Avatar answered Nov 03 '22 07:11

Tomas Votruba