ESLint 在初始化为箭头函数的 class 实例 属性 上显示错误
ESLint shows error on class instance property initialized to arrow function
可能类似于
当class方法定义为箭头函数时Eslint高亮错误'method'未定义。 (无-undef)。
简单的例子
class abc {
d = () => {
// method body
}
}
这里没有定义'd'
我的 .eslintrc 配置
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:flowtype/recommended"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"plugins": [
"react",
"flowtype"
],
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
.babelrc
{
"presets": ["react", "es2015", "stage-1", "flow"]
}
也许我需要声明一些规则?
This is something that hasn't made its way into Javascript yet. It's available as an experimental plugin with babel, so you'll need to change the default parser for eslint with babel-eslint
.
如 所述,我尝试通过命令行 运行 eslint,但我没有看到该错误。
我的编辑器配置错误。 (atom 的 linter-eslint 包中 node_modules 文件夹的路径错误)。删除此路径并重新启动编辑器后一切正常。
可能类似于
当class方法定义为箭头函数时Eslint高亮错误'method'未定义。 (无-undef)。 简单的例子
class abc {
d = () => {
// method body
}
}
这里没有定义'd'
我的 .eslintrc 配置
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:flowtype/recommended"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"plugins": [
"react",
"flowtype"
],
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}
.babelrc
{
"presets": ["react", "es2015", "stage-1", "flow"]
}
也许我需要声明一些规则?
This is something that hasn't made its way into Javascript yet. It's available as an experimental plugin with babel, so you'll need to change the default parser for eslint with babel-eslint
.
如
我的编辑器配置错误。 (atom 的 linter-eslint 包中 node_modules 文件夹的路径错误)。删除此路径并重新启动编辑器后一切正常。