eslint 抱怨 getInitialProps

eslint complaining about getInitialProps

这是我的 .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": {}
}

这是我的组件:

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

Eslint 抱怨 getInitialProps:

Parsing error: Unexpected token getInitialProps

除了添加抑制注释之外,还有什么方法可以让 eslint 接受 getInitialProps 声明?

正如@Scott 在评论中指出的那样,解决方案是添加 babel-eslint,我最终的 .eslintrc 如下:

{
  "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": {}
}