【问题标题】:Globbing not working with gulp eslint with jsx filesGlobbing 不适用于带有 jsx 文件的 gulp eslint
【发布时间】:2015-12-01 16:08:20
【问题描述】:

这是我的lint 任务:

gulp.task('lint', function(){
  gulp.src(fileString)
    .pipe(eslint())
    .pipe(eslint.format());
});

如果fileString'js/**/*.js',它只对 .js 文件进行 lint 处理就可以了。如果是'js/components/**.jsx',它会完美地对 .jsx 进行 lint。但是'js/**/*.jsx''js/**/*/.*{js,jsx}',它会看到所有正确的文件,但对它们没有任何作用。

这是我的 /js 目录(用于 react 项目):

├── stores
│   └── heyStore.jsx
├── models.js
├── mixins.js
├── data
│   └── states.js
├── config.js
├── components
│   ├── firstThing.jsx
│   ├── aThing.jsx
│   ├── whoaWhat.jsx
│   └── nahYo.jsx
├── app.jsx
└── api
    ├── prod.js
    └── mock.js

以防万一,这是我的.eslintrc 文件:

{
  "parser": "babel-eslint",
  "plugins": [
    "react"
  ],
  "ecmaFeatures": {
    "jsx": true,
    "arrowFunctions": true,
    "blockBindings": true,
    "generators": true
  },
  "rules": {
    "strict": 0,
    "no-underscore-dangle": 0,
    "no-unused-vars": 0,
    "curly": 0,
    "no-multi-spaces": 0,
    "key-spacing": 0,
    "no-return-assign": 0,
    "consistent-return": 0,
    "no-shadow": 0,
    "no-comma-dangle": 0,
    "no-use-before-define": 0,
    "no-empty": 0,
    "new-parens": 0,
    "no-cond-assign": 0,
    "quotes": [2, "single", "avoid-escape"],
    "camelcase": 0,
    "semi": [2, "always"],
    "new-cap": [1, { "capIsNew": false }],
    "no-undef": 2
  },
  "env": {
    "browser": true,
    "node": true
  },
  "globals": {
  }
}

【问题讨论】:

    标签: javascript node.js reactjs gulp eslint


    【解决方案1】:

    我找到了修复here

    基本上我的 gulp 任务看起来像:

    gulp.task('lint', function(){
      gulp.src('js/**/*.{js,jsx}')
        .pipe(eslint())
        .pipe(eslint.format())
        .on('data', function(file) {
          if(file.eslint.messages && file.eslint.messages.length){
            gulp.fail = true;
          }
        });
    
    });
    
    process.on('exit', function() {
      if (gulp.fail) {
        process.exit(1);
      }
    });
    

    不过,我不确定为什么需要这样做或为什么要修复它。

    【讨论】:

      【解决方案2】:

      作为 gulp.src 的输入,您可以提供一个 globs 数组。实际上这种组合应该有效:[js/**/*.js, js/**/*.jsx]。如果您只说js/components/**.jsx,也远非理想,请使用适合您的方式:[js/**/*.jsjs/components/**.jsxjs/**.jsxjs/stores/**.jsx]

      【讨论】:

        猜你喜欢
        • 2019-04-30
        • 2020-04-06
        • 1970-01-01
        • 2018-07-04
        • 1970-01-01
        • 1970-01-01
        • 2021-03-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多