olivertappin / phpcs-diff Goto Github PK
View Code? Open in Web Editor NEWDetects violations of a defined set of coding standards based on a git diff
License: MIT License
Detects violations of a defined set of coding standards based on a git diff
License: MIT License
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.' )
When encountering an error via the phpcs
executable, currently the tool returns:
Unable to run phpcs executable.
Which is executed here: https://github.com/olivertappin/phpcs-diff/blob/master/src/PhpcsDiff.php#L144
Whereas the real error could be something like:
ERROR: the "ruleset.xml" coding standard is not installed. The installed coding standards are PEAR, MySource, Squiz, PSR2, Zend, PSR12 and PSR1
Which can be difficult to find.
The suggestion here would be to change this functionality and have the raw error returned to the user, so they're able to see what's going on.
grep: unrecognized option: P
BusyBox v1.31.1 () multi-call binary.
Usage: grep [-HhnlLoqvsriwFE] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]...
Search for PATTERN in FILEs (or stdin)
-H Add 'filename:' prefix
-h Do not add 'filename:' prefix
-n Add 'line_no:' prefix
-l Show only names of files that match
-L Show only names of files that don't match
-c Show only count of matching lines
-o Show only the matching part of line
-q Quiet. Return 0 if PATTERN is found, 1 otherwise
-v Select non-matching lines
-s Suppress open and read errors
-r Recurse
-i Ignore case
-w Match whole words only
-x Match whole lines only
-F PATTERN is a literal (not regexp)
-E PATTERN is an extended regexp
-m N Match up to N times per file
-A N Print N lines of trailing context
-B N Print N lines of leading context
-C N Same as '-A N -B N'
-e PTRN Pattern to match
-f FILE Read pattern from file
No violations to report.
It appears in some jobs, the regular expression to match the changed lines is not selecting all the necessary parts:
travis@travis-job-f6e74a8f-d328-4130-bc86-dbda51998fe9:~/build/my-app$ git diff -U0 origin/my-branch 4e43fa1b5e8eb31455530a8d55f6d72877260342 /home/travis/build/my-app/MyClass.php | grep -E '@@ -[0-9]+(?:,[0-9]+)? \+([0-9]+)(,([0-9]+))? @@'
If we remove the second part of the regular expression (before the space), it matches:
travis@travis-job-f6e74a8f-d328-4130-bc86-dbda51998fe9:~/build/my-app$ git diff -U0 origin/my-branch 4e43fa1b5e8eb31455530a8d55f6d72877260342 /home/travis/build/my-app/MyClass.php | grep -E '@@ -[0-9]+(:,[0-9]+)?,'
@@ -103,0 +104 @@ class MyClass
@@ -106,0 +108,5 @@ class MyClass
@@ -898,0 +905,2 @@ class MyClass
@@ -902,3 +910,16 @@ class MyClass
@@ -906,2 +927,2 @@ class MyClass
@@ -910,0 +932,32 @@ class MyClass
Which suggests what we think is a space, isn't actually a space after all:
@@ -103,0 +104 @@ class MyClass
^ --- here
The regular expression defined here: https://github.com/olivertappin/phpcs-diff/blob/master/src/PhpcsDiff.php#L251 needs to be updated to match these instances.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.