Ale*_*Kim 11 javascript typescript eslint
在我看来,有一个已回答的问题实际上并没有回答这个问题,关于ESLint 中extends: []vs之间plugins: []的区别。
就我而言,我只使用了扩展部分:
extends: [
'plugin:@typescript-eslint/recommended',
],
plugins: [],
rules: {
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
},
],
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我只是使用了预定义的配置,plugin:@typescript-eslint/recommended并@typescript-eslint/explicit-function-return-type在rules: {}部分中覆盖了规则。但是为什么我们需要这个插件部分呢?如果没有它一切正常?我想念什么?
你做得对。
对于您的示例,有两种方法可以添加typescript-eslint...
{
parser: "@typescript-eslint/parser",
parserOptions: { sourceType: "module" },
plugins: ["@typescript-eslint"],
extends: [],
rules: {
"@typescript-eslint/explicit-function-return-type": [
"error",
{
allowExpressions: true
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
{
plugins: [],
extends: ["plugin:@typescript-eslint/recommended"],
rules: {
"@typescript-eslint/explicit-function-return-type": [
"error",
{
allowExpressions: true
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
区别在于...
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为空,也能正常工作。编写良好的插件/配置允许这种情况发生。
| 归档时间: |
|
| 查看次数: |
691 次 |
| 最近记录: |