[英]Only arrow functions in eslint?
您可以使用此 ESLint首選箭頭回調規則,該規則將在任何可以使用箭頭函數而不是函數表達式的地方標記錯誤/警告
Anser 基於@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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.