简体   繁体   English

gulp-eslint 无法解析可选的链接语法

[英]gulp-eslint fails to parse optional chaining syntax

I'm trying to lint JavaScript code with optional chaining syntax like:我正在尝试使用可选的链接语法对 JavaScript 代码进行 lint,例如:

let foo = bar?.property;

When parsing my JS files with eslint explicitly, it passes.当使用eslint显式解析我的 JS 文件时,它通过了。

When parsing with gulp-eslint using the same configuration, linting fails with:使用相同配置解析gulp-eslint ,linting 失败:

Parsing error: Unexpected token .解析错误:意外标记。

My .eslintrc.json file contains:我的.eslintrc.json文件包含:

{
    "parserOptions": {
      "ecmaVersion": 2020
    }
}

My Gulp task looks like:我的 Gulp 任务看起来像:

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 . ecmaVersion 解析器选项不能这样使用,请参阅https://eslint.org/docs/user-guide/configuring/language-options#specifying-environments Changing it from 2020 to 11 or 12 or "latest" should work.将其从 2020 更改为 11 或 12 或“最新”应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM