Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Commit

Permalink
Do not silently fail at syntax error
Browse files Browse the repository at this point in the history
Fixes #15
Closes #16
  • Loading branch information
markelog committed Dec 22, 2013
1 parent 9ceaada commit fe13867
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tasks/jscs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function( grunt ) {
return jscs.check( path );
});

Vow.all( checks ).then(function( results ) {
Vow.any( checks ).then(function( results ) {
jscs.setErrors( concat.apply( [], results ) ).report().notify();

done( options.force ? true : !jscs.count() );
Expand Down
8 changes: 7 additions & 1 deletion tasks/lib/jscs.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ exports.init = function( grunt ) {
* @see Checker#checkPath
*/
JSCS.prototype.check = function( path ) {
return this.checker.checkPath( path );
var checkPath = this.checker.checkPath( path );

checkPath.fail(function( error ) {
grunt.warn( error );
});

return checkPath;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/enmasse.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ exports.fail = function( test ) {
});
};

exports.fail = function( test ) {
grunt.util.spawn({
cmd: "grunt",
args: [ "jscs:broken" ]
}, function( error, result ) {
test.equal( grunt.file.read( "expectations/broken" ), result.stdout );

test.done();
});
};

exports.force = function( test ) {
grunt.util.spawn({
cmd: "grunt",
Expand Down
9 changes: 9 additions & 0 deletions test/enmasse/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ module.exports = function( grunt ) {
config: "../configs/fail.json"
}
},
broken: {
files: {
src: [ "../fixtures/broken.js", "../fixtures/fixture.js" ]
},
options: {
config: "../configs/fail.json",
force: true
}
},
force: {
files: {
src: "../fixtures/fixture.js"
Expand Down
4 changes: 4 additions & 0 deletions test/enmasse/expectations/broken
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Running "jscs:broken" (jscs) task
Warning: Syntax error at ../fixtures/broken.js: Line 3: Unexpected end of input Use --force to continue.

Aborted due to warnings.
3 changes: 3 additions & 0 deletions test/fixtures/broken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
( function ( global ) {

'use strict';
19 changes: 19 additions & 0 deletions test/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,24 @@ module.exports = {

test.done();
});
},

"Don't break on syntax error": function( test ) {
hooker.hook( grunt, "warn", {
pre: function( message ) {
test.ok( message.toString().length, "error message should not be empty" );

test.done();
return hooker.preempt();
},

once: true
});

var jscs = new JSCS({
"requireCurlyBraces": [ "while" ],
});

jscs.check( "test/fixtures/broken.js" );
}
};

0 comments on commit fe13867

Please sign in to comment.