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

javascript - Why gulp-eslint doesn't work? - Stack Overflow

programmeradmin1浏览0评论

I have this task in my gulpfile:

gulp.task('js', function () {
return gulp.src('js/main.js')
    .pipe(eslint({

    }))
    .pipe(browserSync.stream());
});

But when I run it , console is clear.

D:\workflow\training\js_learn\task_1>gulp js                                                  
[19:40:51] Using gulpfile D:\workflow\training\js_learn\task_1\gulpfile.js                    
[19:40:51] Starting 'js'...                                                                   
[19:40:51] Finished 'js' after 302 ms                                                         

But I know, that there are errors in my JS

I have this task in my gulpfile:

gulp.task('js', function () {
return gulp.src('js/main.js')
    .pipe(eslint({

    }))
    .pipe(browserSync.stream());
});

But when I run it , console is clear.

D:\workflow\training\js_learn\task_1>gulp js                                                  
[19:40:51] Using gulpfile D:\workflow\training\js_learn\task_1\gulpfile.js                    
[19:40:51] Starting 'js'...                                                                   
[19:40:51] Finished 'js' after 302 ms                                                         

But I know, that there are errors in my JS

Share Improve this question edited Sep 9, 2015 at 16:52 Gatilin Maxim asked Sep 9, 2015 at 16:45 Gatilin MaximGatilin Maxim 871 silver badge8 bronze badges 2
  • Did you require eslint in your task file? – Christopher Marshall Commented Sep 9, 2015 at 16:46
  • eslint = require('gulp-eslint');? yes, i required it. – Gatilin Maxim Commented Sep 9, 2015 at 16:51
Add a ment  | 

3 Answers 3

Reset to default 4

By default eslint doesn't enforce any rules. For a quick solution, try creating a .eslintrc file using eslint and then customize it as needed.

  1. npm install -g eslint // you may need to sudo for global install, but you should fix that
  2. eslint --init // answer the questions

then edit your .eslintrc file for whatever rules you need (see http://eslint/docs/rules/)

Here's the task I use. It works well. Perhaps your issue is due to the fact that you are passing an empty options object to eslint()?

var eslint = require('gulp-eslint');

return gulp
    .src(config.path.js)
    .pipe(eslint())
    .pipe(eslint.format());

I have a couple of issues with just using eslint like that on all of the files.. But mainly it is just to SLOW!

The solution in my opinion?
Lint only the staged git files that you've currently worked on.

I saw some solutions of doing that, but all of them had 1 problem: they were still too slow!
Most of them tried to use git status for each file to see if we should lint it or not.. so the problem was still that we did some operations on files that we didn't worked on..

So I tried to do just that in our project, here is the example of what I did: gulp-eslint-premit.
It is very fast since it is doing only 1 git status operation, and then lints only the needed files.

It also uses Google's js style guide so no need to define your own rules.. Just use what Google uses..

I hope this helps :-)

发布评论

评论列表(0)

  1. 暂无评论