12

The following code located in a class that extends React.Component

  nextState = () => {
    this.setState({
      state : this.state.state + 1
    });
  };

However ESLint with airbnb rules catches this and throws the following error: error Parsing error: Unexpected token =

I would like to keep this syntax as it allows me to avoid binding this in the constructor.

loganfsmyth
  • 156,129
  • 30
  • 331
  • 251
Cenoc
  • 11,172
  • 21
  • 58
  • 92
  • Possible duplicate of [How do I configure ESLint to allow fat arrow class methods](http://stackoverflow.com/questions/34244888/how-do-i-configure-eslint-to-allow-fat-arrow-class-methods) – rofrol Mar 28 '16 at 20:17

2 Answers2

11

I struggled with this problem for quite a while. I found that this configuration of .eslintrc works for your problem.

{
  "extends": "airbnb",
  "parser": "babel-eslint"
}

It works nicely with Sublime Text 3 with SublimeLinter-contrib-eslint.

Note that you need to npm install -g eslint babel-eslint

put .eslintrc in ~/ for global config, put .eslintrc in app folder to overwrite global config.

also note that: Assignment operation inside class is not part of es6, see this link for discussion

Sida Zhou
  • 3,529
  • 2
  • 33
  • 48
4

You need to specify Language options. For ref: http://eslint.org/docs/user-guide/configuring#specifying-language-options

You can do this with a single command also inside your .eslintrc file.

{
    "env": {
        "es6": true,
        "node": true
    }
}
Gyandeep
  • 12,726
  • 4
  • 31
  • 42