1

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?

Ted Nyberg
  • 7,001
  • 7
  • 41
  • 72
  • gulp-eslint uses ESLint 6. I guess the standalone ESLint you are running must be the newer 8.2 version. – GOTO 0 Nov 19 '21 at 05:32
  • Did you ever figure this out? I'm having the same problem. – dshapiro Sep 29 '22 at 20:14
  • 1
    @dshapiro We have moved away from `gulp` completely since then, but since `gulp-eslint` is 3 years old I'm guessing it's abandoned and was using an older `eslint` version. – Ted Nyberg Sep 30 '22 at 06:58

1 Answers1

0

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.

BalaM314
  • 76
  • 7
  • Thanks, but setting to `2020` is valid according to the docs. If you look under https://eslint.org/docs/user-guide/configuring/language-options#specifying-parser-options it says: "2020 (same as 11)" – Ted Nyberg Nov 16 '21 at 11:15