繁体   English   中英

如何使用 ESLint 指定解析器? 解析错误:意外的令牌,应为“;”

[英]How to specify parser with ESLint? Parsing error: Unexpected token, expected “;”

我的 eslinter.json

{
    "env": {
        "browser": true,
        "es2020": true
    },
    "parser": "babel-eslint",
    "extends": [
        "plugin:react/recommended",
        "airbnb"
    ],
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
    }
}

当我跑

eslint .eslintrc.json

我有解析错误

  2:10  error  Parsing error: Unexpected token, expected ";"

  1 | {
> 2 |     "env": {
    |          ^
  3 |         "browser": true,
  4 |         "es2020": true
  5 |     },

✖ 1 problem (1 error, 0 warnings)

我添加了 babel-eslint 解析器。 相同。 似乎错误是由我的解析器选项和我正在编写的代码(Ubuntu + VSCode)不兼容引起的。

如何解决这个问题?

The error is because you are telling eslint to lint the JavaScript in the .eslintrc.json file … and the file contains JSON, not JavaScript.

如果你想覆盖定位配置文件的正常过程,你可以使用eslint --config your.js但这不是必需的。

暂无
暂无

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

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