0

我有一个项目在不使用 gulp 进行 linting 时显示错误,但在通过 gulp-eslint 进行 linting 时未能显示相同的错误。

gulpfile.js

const gulp = require('gulp');
const inject = require('gulp-inject');  // Should error since this is never used
const eslint = require('gulp-eslint');

// Common paths
const paths = {
  index: './index.html',
  dist: './dist',
  js: '**/*.js',
  nodeModules: 'nodeModules/**'
};

gulp.task('default', ['lint'], function() {
  // place code for your default task here
});

gulp.task('lint', function() {
  return gulp.src([paths.js, '!' + paths.nodeModules])
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
});

.eslintrc.json

{
  "env": {
    "browser": true,
    "es6": true
  },
  "extends": "eslint:recommended",
  "parserOptions": {
    "sourceType": "module"
  },
  "globals": {
    "require": true
  },
  "rules": {
    "indent": ["error", 2],
    "linebreak-style": ["error", "unix"],
    "quotes": ["error", "single"],
    "semi": ["error", "always"],
    "strict": ["error", "safe"]
  }
}

eslint 直接工作,但不是通过 gulp 任务

$ eslint gulpfile.js 

gulpfile.js
  3:7  error  'inject' is assigned a value but never used  no-unused-vars

✖ 1 problem (1 error, 0 warnings)

$ gulp lint
[12:13:29] Using gulpfile ~/Sites/myproject/gulpfile.js
[12:13:29] Starting 'lint'...
[12:13:29] Finished 'lint' after 35 ms

项目结构

- eslintrc.json
- gulpfile.js

为什么我的 gulp 任务不能正确 lint?

编辑

似乎如果我更改为下面的paths.js,它会检查任何子目录中的所有文件

const paths = {
  js: '*/*.js',
};

如果我更改为下面的paths.js,它会检查当前目录中的所有文件

const paths = {
  js: '*.js',
};

我有点疑惑,为什么 **/*.js什么都没有呢?

4

0 回答 0