Php_codesniffer: Report only lines changed from diff

Created on 10 Aug 2015  路  7Comments  路  Source: squizlabs/PHP_CodeSniffer

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

Question

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

All 7 comments

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

For those of you that are reading @exussum12's comment the diffFilter script that is being referred to can be found here.

Was this page helpful?
0 / 5 - 0 ratings