I'm trying to lint JavaScript code with optional chaining syntax like:
let foo = bar?.property;
When parsing my JS files with eslint
explicitly, it passes.
When parsing with gulp-eslint
using the same configuration, linting fails with:
Parsing error: Unexpected token .
My .eslintrc.json
file contains:
{
"parserOptions": {
"ecmaVersion": 2020
}
}
My Gulp task looks like:
const eslint = require('gulp-eslint');
return gulp.src(['src/**/*.js'])
.pipe(eslint({ configFile: '.eslintrc.json' }))
.pipe(eslint.formatEach('compact', process.stderr))
.pipe(eslint.failAfterError());
I'm using the following packages:
"devDependencies": {
"eslint": "^8.2.0",
"gulp": "4.0.2",
"gulp-eslint": "^6.0.0",
}
Am I missing something, or is there a viable workaround?
The ecmaVersion parser option can't be used like that, see https://eslint.org/docs/user-guide/configuring/language-options#specifying-environments. Changing it from 2020 to 11 or 12 or "latest" should work.