如何配置 ESLint 以允许粗箭头类方法 [英] How do I configure ESLint to allow fat arrow class methods
本文介绍了如何配置 ESLint 以允许粗箭头类方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ESLint 在我尝试 lint 我的 Es6 类时抛出 Parsing error: Unexpected token =
错误.我缺少什么配置参数来启用 eslint 中的胖箭头类方法?
ESLint is throwing a Parsing error: Unexpected token =
error when I try to lint my Es6 classes. What configuration parameter am I missing to enable fat arrow class methods in 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) 不支持实验性功能.
If you want to use experimental features (such as arrows as class methods) you need to use babel-eslint
as a parser. Default parser (Espree) doesn't support experimental features.
这篇关于如何配置 ESLint 以允许粗箭头类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文