-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin doesn't fail build #10
Comments
Agreed - will have this done soon |
Just waiting to finish gulp-util PrettyError to make stuff like this look a little better. This will cause peoples stuff to start exiting on error (unless we add a --force) |
I agree it should fail the build, but if it just piped an error into the stream, the build would fail before the reporter got a crack at it. Should it fail |
@robrich What do you guys think about this behavior being off by default (since a jshint error is not really a fatal error) and having a flag that enables this? |
I'd say it's in the eyes of the beholder how fatal the error is, and I'd lean more towards on by default. If your |
What should the error message look like? It won't have access to any reporters |
In my opinion Furthermore, there might be good reasons to habe jslint process all the files in the stream and after that apply some other custom stream to it, which simply uses the generated While I am thinking about it. Why not have a gulp.src("src/**/*.js")
.pipe(jshint())
.pipe(jshint.reporter("default"))
.pipe(jshint.failOnError()); Something like the above would provide a maximum flexibility, while still adhering to the separation of concerns idea, which are one of the reasons streams are used. Right? |
I really like the separation of three tasks: running the linting, reporting on the linting, and failing the build. It seems like a lot of ceremony for typical users though. Adding "fail" to the reporter is a wonderful idea (as I really do want the reporter to run before I fail the build), but all built-in reporters don't do this. (They also log not to events or to the logger of my choice but directly to stdout.) I think because of this, bundling fail with reporting would ultimately not gain traction. |
But, failing a build might be a task Gulp should handle. For example, Gulp-JSHint run linting on each task. Once all files have passed through ( So process continue and other task can be runned like unit tests and such. Once all the streams are done, Gulp either exit 0 with success, or then exit 1 logging all tasks who've failed, e.g.
|
Even though it might be a little confusing for the typical user at first, the three different streams would reflect the whole architecture of Gulp best, I think. Once users understand the architectural idea behind the system, they should easily understand what's going on there. For convenience reasons I don't see a problem with the reporters not having the capability to fail the build, as it is the reporter-stream here, which should take care of doing this. |
@SBoudrias I agree with you maybe failing builds should be handled in a way, which better reflects the stream based architecture of gulp. But I think this belongs into another more general Issue on the Gulp repository itself, as it concerns more than only this plugin. |
That's intriguing: like a "fail the build" flag in gulp that tasks can set that doesn't crash out immediately but rather waits for all orchestrations to finish then crashes. I agree, pitch this as an idea on gulp, and we'll implement it in orchestrator. |
Opened an issue on Gulp about this: gulpjs/gulp#113 |
Also see sindresorhus/jshint-stylish#6 for a temporary fix |
Working on this now. This is where I'm going with it gulp.src("src/**/*.js")
.pipe(jshint())
.pipe(jshint.reporter("default"))
.pipe(jshint.reporter("fail")); I'm just going to include a custom reporter that fails on error |
This is out in 1.4 - let me know if this doesn't work out for everyone |
Works for me, but it throws as soon as an error is encountered. I feel it'd be better if it only throwed once every files passed through; this way we get a full report. |
+1 for getting a full report and then erroring as another option |
Still does not work for me. This returns a status code 0. gulp.task('lintJS', function(){
return gulp.src('./src/app/**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter("fail"));
}); It works when I leave off the return, but that does not seem right to me... Can anyone help me out? Cheers, JH |
+1 for full report and erroring at the end. |
As of 1.5.4 it works if I have a |
I noticed similar behavior to @yeehaa123's issue. The way I've ultimately solved this problem is to watch for errors manually, then var exitCode = 0,
totalLintErrors = 0;
process.on('exit', function () {
process.nextTick(function () {
var msg = "gulp '" + gulp.seq + "' failed";
console.log(gutil.colors.red(msg));
process.exit(exitCode);
});
});
function lintOnEnd() {
var errString = totalLintErrors + '';
if (exitCode) {
console.log(gutil.colors.magenta(errString), 'errors\n');
gutil.beep();
}
}
gulp.task('lint', function () {
return gulp.src([
'./*.js',
'./lib/**/*.js',
'./test/**/*.js'
])
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(map(function (file, cb) {
if (!file.jshint.success) {
totalLintErrors += file.jshint.results.length;
exitCode = 1;
}
cb(null, file);
}))
.on('end', function () {
lintOnEnd();
if (exitCode) {
process.emit('exit');
}
});
}); It feels a bit brute force but I get the advantage of tracking all jshint errors, across all files, in one complete report before exiting: [~/Projects/tesla.lib.core]$ gulp lint
[gulp] Using gulpfile /Users/montgomeryc/Projects/tesla.lib.core/gulpfile.js
[gulp] Starting 'lint'...
/Users/montgomeryc/Projects/tesla.lib.core/lib/service/core/property_service.js
line 135 col 5 The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
line 125 col 3 The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
✖ 2 problems
/Users/montgomeryc/Projects/tesla.lib.core/test/service/inject/dependency-tree-test.js
line 17 col 5 The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
✖ 1 problem
3 errors
[gulp] Finished 'lint' after 1.04 s
gulp 'lint' failed I also created a slight variation, |
As of 1.6.1 I'm still getting an exit code of 0. My config is as follows:
Output:
|
FYI @Aaronius: I have just about the same code as you do. With 1.6.4 it now returns 1. |
Exit codes should work fine now with the latest gulp (global and local) and the latest gulp-jshint |
Confirmed. Thank you! |
@chmontgomery I have used your code, but it says: map is not defined, missing something? Thanks ;) Finally, I have found better fail reporting here: |
@luckylooke I'm missing the require statements in my example. |
@chmontgomery Thank you, could you edit the post for others, just put var map = require('map-stream'); at the begining. It can save someones time I think :) |
@luckylooke You don't have to use his example code because the bug was fixed |
Even if JSHint returns error, the plugins continue without errors.
It'd be best if it returned an error when JSHint fail in order to break a build.
The text was updated successfully, but these errors were encountered: