gulp-jscs
gulp-jscs copied to clipboard
Stop .pipe() chain on linting error?
I'm trying to make gulp-jscs
run on file changes, and - if an error is encountered - just report it, without breaking watch and without continuing the stream (e.g., a file with errors doesn't get uglified and doesn't go to a dest folder). And can't seem to succeed in both with gulp-jscs: either the fail
(and failImmediage
) reporter breaks watch, or, if I catch stream errors, the stream doesn't stop.
I should note that if the error handler is attached after the call to, for example, gulp-uglify
, it works as it should: there is no throw and the stream doesn't continue.
Am I right to assume that it's gulp-jscs
that is unable to do what I need it to do? And if so, is there a way to fix this?
gulp v3.9.0, gulp-jscs v3.0.2, the gulpfile looks like this:
var gulp = require('gulp'),
jscs = require('gulp-jscs'),
uglify = require('gulp-uglify');
gulp.task('js', function(){
gulp.src('js/*.js')
.pipe(jscs())
.pipe(jscs.reporter())
.pipe(jscs.reporter('failImmediately'))
.on('error', function(e){
this.emit('end');
})
.pipe(uglify()) // This should (and everything after) not fire if jscs finds an error. But it does.
.pipe(gulp.dest('dist/js/'));
});
gulp.task('default', function(){
gulp.watch('js/*.js', ['js'])
});