答案 0 :(得分:3)
您可以使用此ESLint prefer-arrow-callback规则,该规则会在可能使用箭头函数而不是函数表达式的任何地方标记错误/警告
答案 1 :(得分:1)
基于@JohannesEwald评论和@KevinAmiranoff答案的分析器。
我正在使用以下规则:
https://www.npmjs.com/package/eslint-plugin-prefer-arrow
https://eslint.org/docs/rules/prefer-arrow-callback
https://eslint.org/docs/rules/func-style
npm install -D eslint-plugin-prefer-arrow
.eslintrc
或package.json
和eslintConfig
:
"plugins": [
"prefer-arrow"
],
"rules": {
"prefer-arrow/prefer-arrow-functions": [
"error",
{
"disallowPrototype": true,
"singleReturnOnly": false,
"classPropertiesAllowed": false
}
],
"prefer-arrow-callback": [
"error",
{ "allowNamedFunctions": true }
],
"func-style": [
"error",
"expression",
{ "allowArrowFunctions": true }
]
}
我认为这真的很好。如果您需要为特定行禁用规则,请按以下步骤操作:
// eslint-disable-next-line func-style, prefer-arrow/prefer-arrow-functions