关于ESLint中extends: []
与plugins: []
之间的区别,我认为答案question并没有真正回答问题。
就我而言,我只是使用了“扩展”部分:
extends: [
'plugin:@typescript-eslint/recommended',
],
plugins: [],
rules: {
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
},
],
}
如您所见,我只是使用了plugin:@typescript-eslint/recommended
中的预定义配置,还覆盖了@typescript-eslint/explicit-function-return-type
部分中的rules: {}
规则。但是,为什么我们需要这个PLUGINS部分呢?如果一切正常,没有它?我想念什么?
答案 0 :(得分:7)
你做对了。
对于您的示例,有两种方法可以添加 UIkit.util.on("#sortable-element", "added moved removed start stop", function(e, sortable) { console.log(e.type); });
...
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
为空也能正常工作。编写良好的插件/配置允许这种情况发生。