简体   繁体   English

错误eslint解析:意外的令牌eslint错误

[英]error eslint parsing: unexpected token eslint error

i am getting unexpected token on the square bracket. 我在方括号中得到了意外的令牌。

i have tried setting the eslint parameters and install babel-eslint but nothing works for me. 我曾尝试设置eslint参数并安装babel-eslint,但对我来说没有任何用。

const [state,dispatch] = useReducer(createUserReducer, 
  {
    email: '',
    password: '',
    verifyPassword: ''
   });


my eslint configuration: 

{
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
      "modules": true,
      "blockBindings": true,
      "experimentalObjectRestSpread": true
    }
  },
  "extends": "rallycoding",
  "rules": {
    "react/require-extension": "off",
    "global-require": 0,
    "no-unused-vars": 0,
    "unexpected-token": 0
  }
}

I should be able to build the code but eslint is throwing error saying unexpected token. 我应该能够构建代码,但是eslint抛出错误,提示意外的令牌。

Please note that supporting JSX syntax is not the same as supporting React . 请注意,支持JSX语法与支持React并不相同。 React applies specific semantics to JSX syntax that ESLint doesn't recognize. React将特定的语义应用于ESLint无法识别的JSX语法。 We recommend using eslint-plugin-react if you are using React and want React semantics. 如果您使用React并需要React语义,建议使用eslint-plugin-react By the same token, supporting ES6 syntax is not the same as supporting new ES6 globals (eg, new types such as Set). 同样,支持ES6语法与支持新的ES6全局变量(例如,诸如Set之类的新类型)并不相同。 For ES6 syntax, use { "parserOptions": { "ecmaVersion": 6 } } ; 对于ES6语法,请使用{ "parserOptions": { "ecmaVersion": 6 } } ; for new ES6 global variables, use { "env": { "es6": true } } . 对于新的ES6全局变量,请使用{ "env": { "es6": true } }

Try these configurations : 尝试以下配置:

eslintrc.js : eslintrc.js:

module.exports = {
      root: true,
      "extends": "eslint:recommended",
    };

eslintrc.json : eslintrc.json:

{
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": [
        "google"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
    }
}

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

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