【问题标题】:How to specify parser with ESLint? Parsing error: Unexpected token, expected ";"如何使用 ESLint 指定解析器?解析错误:意外的令牌,应为“;”
【发布时间】:2021-04-24 00:31:49
【问题描述】:

我的 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)不兼容引起的。

如何解决这个问题?

【问题讨论】:

  • 您似乎正在尝试像 JavaScript 一样对配置文件进行 lint,您的意思是例如eslint -c .eslintrc.json ...?虽然这是默认文件名之一,但您可以完全省略它。

标签: javascript ecmascript-6 eslint


【解决方案1】:

错误是因为您告诉 eslint 对 .eslintrc.json 文件中的 JavaScript 进行 lint 处理……并且该文件包含 JSON,而不是 JavaScript。

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

【讨论】:

    猜你喜欢
    • 2022-01-02
    • 2019-12-25
    • 2017-11-21
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2018-08-14
    相关资源
    最近更新 更多