Is it possible use codesniffer against say git diff, so it only checks new code, like the --diff option in pep8:
https://pep8.readthedocs.org/en/latest/intro.html#example-usage-and-output
No. It might be, that changing line A would result in line B (which isn't changed) start to getting an error. If you just remove errors from non-changed lines you might miss that.
I'm using PHP_CodeSniffer on Jenkins, that runs it on every commit and then compares reports from current and previous commits to see what errors have been added.
Ah that's a nice way to do it! Do you have any pointers to how you set up the sniffer in Jenkins to do that?
You can use http://jenkins-php.org/ Jenkins template for PHP projects. It explains how to configure that. It uses Ant internally, but I've used Phing instead of it because their task file format is compatible.
Awesome thanks @aik099!
Just confirming that PHPCS can't check only changed lines because it requires the entire file contents to tokenize the code and find errors. So using an external script or tool is the way to go.
Try https://github.com/exussum12/coverageChecker
with
git diff origin/master... > diff.txt
phpcs --report=json src > phpcs.json || true
diffFilter --phpcs diff.txt phpcs.json
That should work as expected
Most helpful comment
Try https://github.com/exussum12/coverageChecker
with
git diff origin/master... > diff.txt
phpcs --report=json src > phpcs.json || true
diffFilter --phpcs diff.txt phpcs.json
That should work as expected