How do you configure and use the gulp eslint task?

1.1k Views Asked by At

I'm trying to get gulp-eslint working. Here is my package.json:

"devDependencies": {
    "eslint": "^5.4.0",
    "eslint-plugin-babel": "^5.1.0",
    "gulp": "^3.9.1",
    "gulp-eslint": "^5.0.0",
}

There was no mention of dependencies on the gulp-eslint Github page but when I first ran my gulp lint task, I was prompted to install eslint-plugin-babel so I assume it is required.

Here is my task:

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

gulp.task('lint', function () {
    gulp.src('js/scripts.js)
        .pipe(eslint())
        .pipe(eslint.format())
        .pipe(eslint.failAfterError());
});

Here is my .eslintrc.json:

{
    "parserOptions": {
        "ecmaVersion": 6
    },
    "env": {
        "es6": true
    },
    "rules": {}
}

When I run gulp lint I get this error:

Error: ESLint configuration in .eslintrc is invalid:
- Unexpected top-level property "parseOptions"

The eslint docs use parserOptions so I'm not sure where parseOptions is coming from. What am I missing?

1

There are 1 best solutions below

0
On

I got it working after installing a whole bunch of eslint dependencies.

"devDependencies": {
    "eslint": "^5.4.0",
    "eslint-config-standard": "^11.0.0",
    "eslint-plugin-babel": "^5.1.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-node": "^7.0.1",
    "eslint-plugin-promise": "^4.0.0",
    "eslint-plugin-standard": "^3.1.0",
    "babel-eslint": "^8.2.6",
    "gulp": "^3.9.1",
    "gulp-eslint": "^5.0.0"
}

It seems odd that you'd need this many packages to get eslint working, but this worked for me.