javascript - 如何配置 ESLint 以允许粗箭头类方法

标签 javascript eslint class-fields

ESLint 抛出 Parsing error: Unexpected token = 错误,当我尝试检查我的 Es6 类时。我缺少什么配置参数来启用 eslint 中的粗箭头类方法?

示例类:

class App extends React.Component{
    ...
    handleClick = (evt) => {
        ...
    }
}

.eslint

{
  "ecmaFeatures": {
    "jsx": true,
    "modules":true,
    "arrowFunctions":true,
    "classes":true,
    "spread":true,

  },
  "env": {
    "browser": true,
    "node": true,
    "es6": true
  },
  "rules": {
    "strict": 0,
    "no-underscore-dangle": 0,
    "quotes": [
      2,
      "single"
    ],
  }
}

最佳答案

如果您想使用实验性功能(例如箭头作为类方法),您需要使用 babel-eslint作为解析器。默认解析器 (Espree) 不支持实验性功能。

关于javascript - 如何配置 ESLint 以允许粗箭头类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34244888/

相关文章:

javascript - Javascript 中的 onkeypress + onblur

javascript - Ember : "import Route from ' @ember/routing/route';"throws error in Console

javascript - 将鼠标悬停在带有表格边框的引导表中的单元格上时添加边框

typescript - 为什么 TypeScript 的 'declare global' 会导致 ESLint 错误?

javascript - 如何在 ES6 类中创建 "public static field"?

javascript - JS 类字段

javascript - 为什么 d3 组中具有相同坐标的两个元素不是 100% 重叠?

javascript - 在 Windows 上从 NPM 脚本运行 ESLint

node.js - eslint --fix 在 npm 运行时不起作用