jonathanrz
jonathanrz

Reputation: 4296

eslint complaining about getInitialProps

This is my .eslintrc

{
  "plugins": ["react"],
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "env": {
    "es6": true,
    "browser": true,
    "node": true,
    "mocha": true
  },
  "extends": ["eslint:recommended", "plugin:react/recommended", "standard"],
  "rules": {}
}

This is my component:

class Index extends React.Component {
  static async getInitialProps({ req }) {
    ....
  }
}

Eslint is complaining about getInitialProps:

Parsing error: Unexpected token getInitialProps

There is any way to make eslint accept getInitialProps declaration besides adding a suppress comment?

Upvotes: 4

Views: 542

Answers (1)

jonathanrz
jonathanrz

Reputation: 4296

As pointed out by @Scott in the comments, the solution was to add babel-eslint, my final .eslintrc was the following:

{
  "plugins": ["react"],
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "env": {
    "es6": true,
    "browser": true,
    "node": true,
    "mocha": true
  },
  "extends": ["eslint:recommended", "plugin:react/recommended", "standard"],
  "rules": {}
}

Upvotes: 5

Related Questions