ESLint React 解析错误

ESLint React Parsing Error

所以我按照 guide.meteor.com 中的说明设置了我的 package.json eslintConfig。

"eslintConfig": {
  "plugins": [
    "meteor"
  ],
  "extends": [
    "airbnb/base",
    "plugin:meteor/recommended"
  ],
  "rules": {
    "meteor/eventmap-params": [
      2,
      {
        "templateInstanceParamName": "instance"
      }
    ],
    "import/no-unresolved": [
      2,
      {
        "ignore": [
          "^meteor/"
        ]
      }
    ],
    "semi": [
      "error",
      "never"
    ]
  }
}

在我尝试使用 React 之前它工作正常。

main.js:

Meteor.startup(() => {
  render(<App />, document.getElementById('render-target'))
})

抛出错误:[eslint] Parsing error: Unexpected token <

我有反应插件:

"devDependencies": {
  "eslint": "^2.9.0",
  "eslint-config-airbnb": "^8.0.0",
  "eslint-plugin-import": "^1.6.1",
  "eslint-plugin-jsx-a11y": "^1.0.4",
  "eslint-plugin-meteor": "^3.5.2",
  "eslint-plugin-react": "^5.0.1"
}

我已尝试遵循 Google 中的示例,但其中 none 有所帮助。我尝试将 'react' 和 'eslint-plugin-react' 添加到插件位,但没有任何改变。我很惊讶流星指南的 ESLint 部分没有提供解决方案。如有任何帮助,我们将不胜感激。

安装 babel-eslint 并在 .eslintrc 中添加 "parser": "babel-eslint"。您缺少 ES6 转译,所以 eslint 崩溃了。

您不需要安装 babel-eslint。 Espree(原生 ESLint 解析器)完全支持 ES6、ES7 和 Object Rest/Spread。 ESLint 停止解析你的文件的原因是因为你没有启用 jsx,所以它会认为它是一个不正确的语法。

{
  "ecmaFeatures": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "jsx": true
  }
}

将上面的代码片段添加到您的配置文件中,它应该会开始工作。更多信息,您可以阅读Specifying Parser Options