javascript - How do I run gulp eslint continuously and automatically while fixing files -- how to set up watch -
i trying eslint gulp. have set task this:
gulp.task('lint', function () { return gulp.src([ 'components/myjs.js' ]) // eslint() attaches lint output eslint property // of file object can used other modules. .pipe(eslint()) // eslint.format() outputs lint results console. // alternatively use eslint.formateach() (see docs). .pipe(eslint.format()) // have process exit error code (1) on // lint error, return stream , pipe failonerror last. .pipe(eslint.failonerror()); });
when run gulp lint
tells me lot of errors. trying fix them 1 one. have re-run gulp lint
manually give me updated report. how set automatically re-run every time update 'components/myjs.js'
?
just add watch task:
gulp.task('watch', function() { gulp.watch('components/myjs.js', ['lint']); });
this way gulp track changes on 'components/myjs.js'
, execute 'lint'
task on change
if want further reading: https://scotch.io/tutorials/automate-your-tasks-easily-with-gulp-js