简体   繁体   English

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

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

My eslinter.json我的 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": {
    }
}

When I run当我跑

eslint .eslintrc.json

I have parsing error我有解析错误

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

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

✖ 1 problem (1 error, 0 warnings)

I have added babel-eslint parser.我添加了 babel-eslint 解析器。 The same.相同。 It seems that errors are caused by incompatibilities in my parser options and the code I am writing(Ubuntu + VSCode).似乎错误是由我的解析器选项和我正在编写的代码(Ubuntu + VSCode)不兼容引起的。

How to fix this?如何解决这个问题?

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

If you want to override the normal process for locating the config file, you can use eslint --config your.js but that shouldn't be needed.如果你想覆盖定位配置文件的正常过程,你可以使用eslint --config your.js但这不是必需的。

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

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