Skip to content

Commit 00e57b6

Browse files
committed
PHPCS 3.0 will throw exit code 2 for fixable errors
See squizlabs/PHP_CodeSniffer#930
1 parent ef7f9bb commit 00e57b6

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ var buildCommand = function(opts) {
5656
args.push('--colors');
5757
}
5858

59+
// Finally specify the file is streamed on stdin.
60+
args.push('-');
61+
5962
return {
6063
bin: opts.bin || 'phpcs',
6164
args: args
@@ -202,8 +205,8 @@ var phpcsPlugin = function(options) {
202205
return;
203206
}
204207

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

221-
if (exitCode === 1) {
224+
if ((exitCode === 1) || (exitCode === 2)) {
222225
// A codding style problem is found. Attache report to the file to allow
223226
// reporters do their job.
224227
report.error = true;

test/fixture/error

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
cat > /dev/null
55
# It's just an arbitrary text.
66
echo "This is a test error."
7-
# PHPCS uses exit-codes greater than 1 to report about real errors.
8-
exit 2
7+
# PHPCS uses exit-codes greater than 2 to report about real errors.
8+
exit 3

test/specs/index.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('PHPCS', function() {
215215

216216
plugin.on('data', function(file) {
217217
var output = file.phpcsReport.output.trim();
218-
expect(output).to.be.equal('');
218+
expect(output).to.be.equal('-');
219219
done();
220220
});
221221

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

231231
plugin.on('data', function(file) {
232232
var output = file.phpcsReport.output.trim();
233-
expect(output).to.be.equal('--severity=0');
233+
expect(output).to.be.equal('--severity=0 -');
234234
done();
235235
});
236236

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

246246
plugin.on('data', function(file) {
247247
var output = file.phpcsReport.output.trim();
248-
expect(output).to.be.equal('--warning-severity=1');
248+
expect(output).to.be.equal('--warning-severity=1 -');
249249
done();
250250
});
251251

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

261261
plugin.on('data', function(file) {
262262
var output = file.phpcsReport.output.trim();
263-
expect(output).to.be.equal('--error-severity=2');
263+
expect(output).to.be.equal('--error-severity=2 -');
264264
done();
265265
});
266266

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

276276
plugin.on('data', function(file) {
277277
var output = file.phpcsReport.output.trim();
278-
expect(output).to.be.equal('--standard=PSR2');
278+
expect(output).to.be.equal('--standard=PSR2 -');
279279
done();
280280
});
281281

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

291291
plugin.on('data', function(file) {
292292
var output = file.phpcsReport.output.trim();
293-
expect(output).to.be.equal('--encoding=utf8');
293+
expect(output).to.be.equal('--encoding=utf8 -');
294294
done();
295295
});
296296

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

306306
plugin.on('data', function(file) {
307307
var output = file.phpcsReport.output.trim();
308-
expect(output).to.be.equal('-s');
308+
expect(output).to.be.equal('-s -');
309309
done();
310310
});
311311

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

321321
plugin.on('data', function(file) {
322322
var output = file.phpcsReport.output.trim();
323-
expect(output).to.be.equal('');
323+
expect(output).to.be.equal('-');
324324
done();
325325
});
326326

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

344344
done();
345345
});
@@ -355,7 +355,7 @@ describe('PHPCS', function() {
355355

356356
plugin.on('data', function(file) {
357357
var output = file.phpcsReport.output.trim();
358-
expect(output).to.be.equal('');
358+
expect(output).to.be.equal('-');
359359
done();
360360
});
361361

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

371371
plugin.on('data', function(file) {
372372
var output = file.phpcsReport.output.trim();
373-
expect(output).to.be.equal('');
373+
expect(output).to.be.equal('-');
374374
done();
375375
});
376376

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

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

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

404404
plugin.on('data', function(file) {
405405
var output = file.phpcsReport.output.trim();
406-
expect(output).to.be.equal('');
406+
expect(output).to.be.equal('-');
407407
done();
408408
});
409409

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

419419
plugin.on('data', function(file) {
420420
var output = file.phpcsReport.output.trim();
421-
expect(output).to.be.equal('');
421+
expect(output).to.be.equal('-');
422422
done();
423423
});
424424

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

434434
plugin.on('data', function(file) {
435435
var output = file.phpcsReport.output.trim();
436-
expect(output).to.be.equal('--colors');
436+
expect(output).to.be.equal('--colors -');
437437
done();
438438
});
439439

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

449449
plugin.on('data', function(file) {
450450
var output = file.phpcsReport.output.trim();
451-
expect(output).to.be.equal('');
451+
expect(output).to.be.equal('-');
452452
done();
453453
});
454454

0 commit comments

Comments
 (0)