ESLint 规则被忽略
ESLint rule being ignored
只是想拥有一个 SFC,而 ESLint 却在抱怨
我在 .eslinrc
中有规则
{
"env": {
"es6": true,
"browser": true
},
"extends": "airbnb",
"rules": {
"semi": [2, "never"],
"no-unexpected-multiline": 2,
"no-console": 0,
"react/prefer-stateless-function": [0, {
"ignorePureComponents": true
}],
"comma-dangle": ["error", "never"],
"arrow-body-style": ["error", "never"]
}
}
甚至直接在错误上方添加了 /* eslint arrow-body-style: ["error", "never"]*/
,还有其他人遇到过这个吗?
我做错了什么
您可以在导出之前使用禁用下一行:
// eslint-disable-next-line arrow-body-style
export onst Hi = () > {
[...]
}
也许您也可以尝试在您的 .eslinrc 中将 "arrow-body-style": ["error", "never"]
替换为 "arrow-body-style": "off"
。
顺便说一句,如果您只想避免此错误,请将您的代码替换为以下内容:
import React from 'react';
export const Hi = () => (
<div>
<h1>Hi</h1>
</div>
);
export default Hi;
只是想拥有一个 SFC,而 ESLint 却在抱怨
我在 .eslinrc
{
"env": {
"es6": true,
"browser": true
},
"extends": "airbnb",
"rules": {
"semi": [2, "never"],
"no-unexpected-multiline": 2,
"no-console": 0,
"react/prefer-stateless-function": [0, {
"ignorePureComponents": true
}],
"comma-dangle": ["error", "never"],
"arrow-body-style": ["error", "never"]
}
}
甚至直接在错误上方添加了 /* eslint arrow-body-style: ["error", "never"]*/
,还有其他人遇到过这个吗?
我做错了什么
您可以在导出之前使用禁用下一行:
// eslint-disable-next-line arrow-body-style
export onst Hi = () > {
[...]
}
也许您也可以尝试在您的 .eslinrc 中将 "arrow-body-style": ["error", "never"]
替换为 "arrow-body-style": "off"
。
顺便说一句,如果您只想避免此错误,请将您的代码替换为以下内容:
import React from 'react';
export const Hi = () => (
<div>
<h1>Hi</h1>
</div>
);
export default Hi;