How to run gulp eslint continuously and automatically when fixing files - how to set the clock

I am trying to use eslint with gulp. I created a task like this:

gulp.task('lint', function () { return gulp.src([ 'components/myjs.js' ]) // eslint() attaches the lint output to the eslint property // of the file object so it can be used by other modules. .pipe(eslint()) // eslint.format() outputs the lint results to the console. // Alternatively use eslint.formatEach() (see Docs). .pipe(eslint.format()) // To have the process exit with an error code (1) on // lint error, return the stream and pipe to failOnError last. .pipe(eslint.failOnError()); }); 

when I run gulp lint This tells me a lot of mistakes. Now I am trying to fix them one by one. But I need to re-run gulp lint manually so that it gives me an updated report. How to configure it so that it automatically restarts every time you update 'components/myjs.js' ?

+5
source share
1 answer

Just add a view task:

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

This way, Gulp will track any changes to your 'components/myjs.js' and complete your 'lint' task with any changes

If you want to continue reading: https://scotch.io/tutorials/automate-your-tasks-easily-with-gulp-js

+7
source

All Articles