1

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.

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.

hong developer
  • 13,291
  • 4
  • 38
  • 68
patrick
  • 113
  • 1
  • 8

2 Answers2

1

Please note that supporting JSX syntax is not the same as supporting React. React applies specific semantics to JSX syntax that ESLint doesn’t recognize. We recommend using eslint-plugin-react if you are using React and want React semantics. By the same token, supporting ES6 syntax is not the same as supporting new ES6 globals (e.g., new types such as Set). For ES6 syntax, use { "parserOptions": { "ecmaVersion": 6 } }; for new ES6 global variables, use { "env": { "es6": true } }.

hong developer
  • 13,291
  • 4
  • 38
  • 68
  • I don't see how this relates to the code in the question, which doesn't use jsx at all? – Bergi Aug 20 '19 at 03:53
  • @Bergi The questioner wants to use parameters globally. But like my answer, React does not automatically activate the entire ES6. – hong developer Aug 20 '19 at 04:25
0

Try these configurations :

eslintrc.js :

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

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": {
    }
}
Nirvana
  • 63
  • 3
  • 10