最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I run gulp eslint continuously and automatically while fixing files -- how to set up watch - Stack Overflow

programmeradmin0浏览0评论

I am trying eslint with gulp. I have set up a task like this:

            gulp.task('lint', function () {
                return gulp.src([
            'ponents/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 It tells me a lot of errors. Now I am trying to fix them one by one. But I have to re-run gulp lint manually for it to give me an updated report. How do I set it up so that it will automatically re-run every time I update 'ponents/myjs.js'?

I am trying eslint with gulp. I have set up a task like this:

            gulp.task('lint', function () {
                return gulp.src([
            'ponents/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 It tells me a lot of errors. Now I am trying to fix them one by one. But I have to re-run gulp lint manually for it to give me an updated report. How do I set it up so that it will automatically re-run every time I update 'ponents/myjs.js'?

Share Improve this question edited Apr 27, 2015 at 21:02 Felipe Skinner 16.6k2 gold badges26 silver badges31 bronze badges asked Apr 27, 2015 at 20:32 techguy2000techguy2000 5,1816 gold badges37 silver badges53 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Just add a watch task:

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

This way Gulp will track any changes on your 'ponents/myjs.js' and execute your 'lint' task on any change

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论