jscs-dev/gulp-jscs

Don't fail task

Closed this issue · 4 comments

I kinda like this option in gulp-jshint https://github.com/spalger/gulp-jshint#fail-reporter So the task doesn't have to fail if not specified. Is it standard for gulp? Do you think it's a good idea to implement it here?

I usually combine gulp-jshint and gulp-jscs in my projects but the settings look completely inconsistent (I expect them to have similar apis).

Yeah, this depends on #66.

So I've been learning gulp, and started out by making out a simple script to help improve my development workflow. As you can see in the code I'm using the gulp plugin run-sequence to force that each task run consecutively, rather than concurrently. I think the issue I have come across is along the lines of the feature that stevemao has requested.

Listed below is code that works, but let me explain the issue I came across. My watch task has a runSequence call that has three tasks specified. Without the .on('error',handleJscsError); call in the jscs task, any tasks specified after the jscs task in the runSequence are never called with the exception of the callback specified at the end of the runSequence parameter list. It would be nice if jscs worked much like jshint where if issues are found with watched files, it doesn't break any subsequence calls. However, even without the jshint.reporter('fail') specified for jshint, if jshint finds an issue to report, it doesn't break any subsequent calls. So although I do wish we had an option to do something like jscs.reporter('fail'), even without it, a simple call to jscs shouldn't break.

/* File: gulpfile.js */

/* grab the packages we will be using */
var gulp = require('gulp');
var gUtil = require('gulp-util');
var jscs = require('gulp-jscs');
var jsHint = require('gulp-jshint');
var jsHintStylish = require('jshint-stylish');
var runSequence = require('run-sequence');
var console = require('better-console');

// JSCS error handler
var handleJscsError = function(err) {
    console.log("Error: " + err.toString());
    this.emit('end');
}

// configure the default task and add the watch task to it
gulp.task('default', ['watch']);

// configure the jscs task
gulp.task('jscs', function() {
    return gulp.src('src/app/**/*.js')
        .pipe(jscs('.jscsrc'))
        .on('error',handleJscsError);
});

// configure the lint task
gulp.task('lint', function() {
    return gulp.src("src/app/**/*.js")
        .pipe(jsHint('.jshintrc'))
        .pipe(jsHint.reporter(jsHintStylish));
});

gulp.task('build', function() {

})

// configure the watch task - set up which files to watch and what tasks to use when those files change
gulp.task('watch', function() {

    // setup a watch against the files that need to be checked on save
    return gulp.watch('src/app/**/*.js', function(){

        // Clear console so only current issues are shown
        console.clear();

        // Execute tasks to check code for issues
        runSequence('jscs','lint','build',function(){
            console.log("Tasks Completed.")
        });

    });

});

I originally posted this issue on Stack Overflow hoping to get help on the issue, but after I found a resolution for it, I posted the answer to the question.

My apologies if what I have stated is unclear or require further explanation. I'm new to gulp and want to do my best to help you guys out in improving this useful tool. Cheers.

+1 thank you for the solution but I agree that gulp-jscs should behave more like jshint and not break subsequent tasks on failure by default