olivertappin / phpcs-diff

Detects violations of a defined set of coding standards based on a git diff
MIT License
12 stars 13 forks source link

PhpcsDiff doesn't return a non-zero exit code when violations are reported #2

Closed olivertappin closed 6 years ago

olivertappin commented 6 years ago

Example from a Travis CI console output:

$ if [ ! -z "$TRAVIS_PULL_REQUEST_BRANCH" ]; then phpcs-diff $TRAVIS_BRANCH; else echo "This test does not derive from a pull-request. Unable to run phpcs-diff."; fi;
########## START OF PHPCS CHECK ##########
module/MyModule/src/MyClass/Something.php
 - Line 179 (WARNING) Line exceeds 120 characters; contains 184 characters
 - Line 202 (WARNING) Line exceeds 120 characters; contains 179 characters
 - Line 237 (WARNING) Line exceeds 120 characters; contains 155 characters
 - Line 251 (ERROR) Multi-line function call not indented correctly; expected 32 spaces but found 40
 - Line 251 (ERROR) Closing parenthesis of a multi-line function call must be on a line by itself
########### END OF PHPCS CHECK ###########
The command "if [ ! -z "$TRAVIS_PULL_REQUEST_BRANCH" ]; then phpcs-diff $TRAVIS_BRANCH; else echo "This test does not derive from a pull-request. Unable to run phpcs-diff."; fi;" exited with 0.

The issue here is https://github.com/olivertappin/phpcs-diff/blob/master/src/PhpcsDiff.php#L187 does not return a non-zero exit code when showing the violations.

An alternative (in the mean time) could be to validate the success response:

phpcs-diff $TRAVIS_BRANCH | (! grep -v 'No violations to report.' )