如何配置ESLint以允许胖箭头类方法 [英] How do I configure ESLint to allow fat arrow class methods
本文介绍了如何配置ESLint以允许胖箭头类方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ESLint正在抛出一个解析错误:意外的令牌=
错误,当我尝试lint我的Es6类。我缺少什么配置参数,以在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屋!
查看全文