Skip to content

Commit

Permalink
PHPCS 3.0 will throw exit code 2 for fixable errors
Browse files Browse the repository at this point in the history
  • Loading branch information
arnested committed May 17, 2017
1 parent ef7f9bb commit 00e57b6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ var buildCommand = function(opts) {
args.push('--colors');
}

// Finally specify the file is streamed on stdin.
args.push('-');

return {
bin: opts.bin || 'phpcs',
args: args
Expand Down Expand Up @@ -202,8 +205,8 @@ var phpcsPlugin = function(options) {
return;
}

if (exitCode > 1) {
// On codding style problems Code Sniffer should exists with "1" code.
if (exitCode > 2) {
// On codding style problems Code Sniffer should exists with "1" or "2" code.
// All other non-zero exit codes should be treated as Code Sniffer errors.
var phpcsError = new gutil.PluginError('gulp-phpcs', 'Execution of Code Sniffer Failed');
phpcsError.stdout = output;
Expand All @@ -218,7 +221,7 @@ var phpcsPlugin = function(options) {
output: ''
};

if (exitCode === 1) {
if ((exitCode === 1) || (exitCode === 2)) {
// A codding style problem is found. Attache report to the file to allow
// reporters do their job.
report.error = true;
Expand Down
4 changes: 2 additions & 2 deletions test/fixture/error
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
cat > /dev/null
# It's just an arbitrary text.
echo "This is a test error."
# PHPCS uses exit-codes greater than 1 to report about real errors.
exit 2
# PHPCS uses exit-codes greater than 2 to report about real errors.
exit 3
36 changes: 18 additions & 18 deletions test/specs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('');
expect(output).to.be.equal('-');
done();
});

Expand All @@ -230,7 +230,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('--severity=0');
expect(output).to.be.equal('--severity=0 -');
done();
});

Expand All @@ -245,7 +245,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('--warning-severity=1');
expect(output).to.be.equal('--warning-severity=1 -');
done();
});

Expand All @@ -260,7 +260,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('--error-severity=2');
expect(output).to.be.equal('--error-severity=2 -');
done();
});

Expand All @@ -275,7 +275,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('--standard=PSR2');
expect(output).to.be.equal('--standard=PSR2 -');
done();
});

Expand All @@ -290,7 +290,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('--encoding=utf8');
expect(output).to.be.equal('--encoding=utf8 -');
done();
});

Expand All @@ -305,7 +305,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('-s');
expect(output).to.be.equal('-s -');
done();
});

Expand All @@ -320,7 +320,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('');
expect(output).to.be.equal('-');
done();
});

Expand All @@ -336,10 +336,10 @@ describe('PHPCS', function() {
plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
// Validate the option.
expect(output).to.match(/^--sniffs=/);
expect(output).to.match(/^--sniffs=([^\s]+) -$/);
// Validate used sniffs.
var usedSniffs = output.split('=')[1].split(',');
expect(usedSniffs).to.have.members(['foo', 'bar', 'baz']);
var usedSniffs = /^--sniffs=([^\s]+) -$/.exec(output);
expect(usedSniffs[1].split(',')).to.have.members(['foo', 'bar', 'baz']);

done();
});
Expand All @@ -355,7 +355,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('');
expect(output).to.be.equal('-');
done();
});

Expand All @@ -370,7 +370,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('');
expect(output).to.be.equal('-');
done();
});

Expand All @@ -385,7 +385,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
var excludeArgs = /^--exclude=([^\s]+)$/.exec(output);
var excludeArgs = /^--exclude=([^\s]+) -$/.exec(output);
expect(excludeArgs).to.be.not.null;
expect(excludeArgs[1].split(',')).to.have.members(['foo', 'bar', 'baz']);

Expand All @@ -403,7 +403,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('');
expect(output).to.be.equal('-');
done();
});

Expand All @@ -418,7 +418,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('');
expect(output).to.be.equal('-');
done();
});

Expand All @@ -433,7 +433,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('--colors');
expect(output).to.be.equal('--colors -');
done();
});

Expand All @@ -448,7 +448,7 @@ describe('PHPCS', function() {

plugin.on('data', function(file) {
var output = file.phpcsReport.output.trim();
expect(output).to.be.equal('');
expect(output).to.be.equal('-');
done();
});

Expand Down

0 comments on commit 00e57b6

Please # to comment.