gulp-jscs icon indicating copy to clipboard operation
gulp-jscs copied to clipboard

How can I use fix:true with a watch?

Open jared-christensen opened this issue 8 years ago • 0 comments

Im trying to use gulp and jscs to prevent code smell. I also want to use watch so that this happens when ever a change is made. The problem I'm running into is jscs is modify the source file that is being watched. This causes gulp to go into an infinite loop of jscs modifying the file and then watch seeing the change and firing off jscs again and again and again ... I was wondering how watch and fix can be used together.

const gulp = require('gulp');

gulp.task('lint', function() {
    return gulp.src('/src/**/*.js')
        .pipe(jscs({
            fix: true
        }))
        .pipe(jscs.reporter())
        .pipe(gulp.dest('/src'));
});

gulp.task('watch', function() {
    gulp.watch('/src/**/*.js', ['lint']);
});

jared-christensen avatar Jun 03 '16 14:06 jared-christensen