0

I have a project that shows an error when linting without gulp, but fails to show the same error when linting via gulp-eslint.

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 directly works, but not via gulp task

$ 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

project structure

- eslintrc.json
- gulpfile.js

Why does my gulp task not lint properly?

EDIT

Seems that if I change to paths.js below, it lints all files in any subdir

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

If i change to paths.js below, it lints all files in the current dir

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

I'm a bit puzzled why **/*.js doesn't lint anything?

Catfish
  • 18,876
  • 54
  • 209
  • 353
  • Works for me... maybe some problem with versions? I have gulp 3.9.1, gulp-eslint 3.0.1, gulp-inject 4.2.0 running under node 6.9.1 and npm 3.10.8 – Kryten Feb 21 '17 at 19:00
  • Does it print out an error for you? – Catfish Feb 21 '17 at 19:51
  • ESLint correctly reports the `no-unused-vars` error when I run `gulp lint` – Kryten Feb 21 '17 at 19:59
  • Hmm yea that's what I would expect. Here's the version i'm using: ` $ npm list --depth=0 ├── eslint@3.16.0 ├── gulp@3.9.1 ├── gulp-eslint@3.0.1 ├── gulp-inject@4.2.0 └── wiredep@4.0.0 $ node -v v6.9.1 $ npm -v 3.10.8` – Catfish Feb 21 '17 at 20:36
  • k, I'm stumped. Only other thing I can think of is maybe delete `node_modules` and reinstall everything. – Kryten Feb 21 '17 at 21:34

0 Answers0