[英]ESLint extends vs plugins v2020
有一個已回答的問題在我看來實際上並沒有回答這個問題,關於 ESLint 中的extends: []
與plugins: []
之間的區別。
就我而言,我只是使用了擴展部分:
extends: [
'plugin:@typescript-eslint/recommended',
],
plugins: [],
rules: {
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
},
],
}
如您所見,我只是使用了plugin:@typescript-eslint/recommended
中的預定義配置,並且還覆蓋了rules: {}
部分中@typescript-eslint/explicit-function-return-type
規則。 但是為什么我們需要這個 PLUGINS 部分呢? 如果沒有它一切正常? 我想念什么?
你做對了。
對於您的示例,有兩種方法可以添加typescript-eslint
...
{
parser: "@typescript-eslint/parser",
parserOptions: { sourceType: "module" },
plugins: ["@typescript-eslint"],
extends: [],
rules: {
"@typescript-eslint/explicit-function-return-type": [
"error",
{
allowExpressions: true
}
]
}
}
{
plugins: [],
extends: ["plugin:@typescript-eslint/recommended"],
rules: {
"@typescript-eslint/explicit-function-return-type": [
"error",
{
allowExpressions: true
}
]
}
}
不同的是...
parser
, parserOptions
和plugins
是手動添加的,@typescript-eslint/explicit-function-return-type
。plugin:@typescript-eslint/recommended
已自動添加parser
、 parserOptions
和plugins
。@typescript-eslint/explicit-function-return-type
被擴充和強制執行。 這就是為什么當你使用plugin:@typescript-eslint/recommended
時,即使plugins
為空,事情也能正常工作。 編寫良好的插件/配置允許這種情況發生。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.