【问题标题】:gulp-eslint not throwing any error on consolegulp-eslint 不会在控制台上抛出任何错误
【发布时间】:2016-12-13 23:56:47
【问题描述】:

我正在与gulpreactjs 合作。我添加了eslint 用于对我的代码进行静态分析。我使用gulp-eslint如下:

var eslint = require('gulp-eslint');
gulp.task('eslint', function() {
  // Process all script files, but ignore npm_modules
  gulp.src(['widgets/**/*.js', 'server/**/*.js', '!node_modules/**'])
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());

我的.eslintrc 文件是:

{
  "parser": "babel-eslint",
  "plugins": [
  "react"
],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
  "jsx": true
}
},
"extends": ["eslint:recommended", "plugin:react/recommended"],
"env": {
"browser": true,
"amd": true,
"es6": true,
"node": true,
"mocha": true
},
"rules": {
"comma-dangle": 1,
"quotes": [ 1, "single" ],
"no-undef": 1,
"global-strict": 0,
"no-extra-semi": 1,
"no-underscore-dangle": 0,
"no-console": 1,
"no-unused-vars": 1,
"no-trailing-spaces": [1, { "skipBlankLines": true }],
"no-unreachable": 1,
"no-alert": 0,
"react/jsx-uses-react": 1,
"react/jsx-uses-vars": 1
}
}

但是,即使我的代码中有尾随空格和警报,它也不会在控制台上显示任何错误。它所做的只是:

Starting 'eslint'...
Finished 'eslint' after 1.97 s

目录结构为:

root/
node_modules
widgets //contains the js files
server //contains the js files
.eslintrc
gulpfile.js
package.json

【问题讨论】:

    标签: javascript reactjs gulp eslint


    【解决方案1】:

    您忘记正确传递estlint()。试试:

    var eslint = require('gulp-eslint');
    gulp.task('eslint', function() {
      // Process all script files, but ignore npm_modules
      gulp.src(['widgets/**/*.js', 'server/**/*.js', '!node_modules/**'])
        .pipe(eslint({
          useEslintrc: true
        }))
        .pipe(eslint.format())
        .pipe(eslint.failAfterError());
    

    【讨论】:

    • 试图明确设置useEslintrc 选项?我已经更新了我的答案。另外,请显示您的目录结构。
    • 您不介意通过更新问题来显示目录结构吗?它会更具可读性。
    • 我刚刚注意到.eslintrc 中有"no-alert": 0, 规则。这意味着eslint 将允许警报。您能否还提供您尝试使用eslint 分析的代码?
    • render:function() { var a;变量 b=10;警报(b);
    • 尝试测试上面的代码..但没有对未使用的变量发出警告
    猜你喜欢
    • 2019-04-18
    • 2019-08-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-31
    • 2018-08-06
    • 2017-05-20
    • 1970-01-01
    • 2017-03-08
    相关资源
    最近更新 更多