sirbrillig / phpcs-changed

🐘 Run phpcs on files and only report new warnings/errors compared to the previous version.
MIT License
31 stars 11 forks source link

Phpcs-changed may report unchanged issues when --git-base is used #42

Closed anomiex closed 3 years ago

anomiex commented 3 years ago

The intended use of the --git-base is something like phpcs-changed --git --git-base=master files... to find only the issues that have been added since the current branch was branched from master.

This is accomplished by running phpcs against the version of each file from master and from HEAD, and using git diff master...HEAD to get a diff to correct line number discrepancies.

The problem is that git diff master...HEAD compares the merge-base of master and HEAD with the version in HEAD, but phpcs-changed is run against the version in master itself. If there are changes in master that have not yet been merged into HEAD, the diff will not reflect them but the phpcs run will, which can break the line number correction and cause existing warnings to be incorrectly reported.

Test case

Expected output

No output. Command exits with code 0.

Actual output

FILE: test.php
-----------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 0 WARNINGS AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------
 9 | ERROR | Space after opening parenthesis of function call prohibited
 9 | ERROR | Expected 0 spaces before closing parenthesis; 1 found
-----------------------------------------------------------------------------------------------

Command exits with code 1.