因此,此规则的目的是确保导出的模块对外部使用它的任何人都有清晰的接口。来自规则页面 https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md,使用起来似乎有意义.ts
文件而不是.vue
文件,但您可以根据您的项目需求来判断。
对于我的项目,我使用了建议overrides配置 https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md#configuring-in-a-mixed-jsts-codebase:
{
"rules": {
// disable the rule for all files
"@typescript-eslint/explicit-module-boundary-types": "off"
},
"overrides": [
{
// enable the rule specifically for TypeScript files
"files": ["*.ts", "*.tsx"],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": ["error"]
}
}
]
}
除此之外,我认为你不能拥有filters
因为说on the caught .vue files by eslint, only apply the rule on the ones matched by: 'having <script lang="ts">'
.
也许你最好使用内嵌评论 https://eslint.org/docs/user-guide/configuring/#disabling-rules-with-inline-comments对于这些具体错误。
Edit
我看到的另一个解决方案可能是手动列出您的文件.eslint.config
file.
See Also
- 使用类型感知规则扩展 TypeScript linting https://github.com/typescript-eslint/typescript-eslint/blob/main/docs/linting/README.md#type-aware-rules
- 我收到错误消息,告诉我“该文件必须至少包含在所提供的项目之一中” https://github.com/typescript-eslint/typescript-eslint/blob/main/docs/linting/TYPED_LINTING.md#i-get-errors-telling-me-the-file-must-be-included-in-at-least-one-of-the-projects-provided
如果您确实想使用类型感知 linting 对文件进行 lint:
检查您提供给 parserOptions.project 的每个 tsconfig 的包含选项 - 您必须确保所有文件都与包含 glob 匹配,否则我们的工具将无法找到它。
如果您的文件不应该是现有 tsconfig 之一的一部分(例如,它是存储库本地的脚本/工具),请考虑在您的文件中创建一个新的 tsconfig(我们建议将其称为 tsconfig.eslint.json)项目根目录在其包含中列出了该文件。有关示例,您可以查看我们在此存储库中使用的配置:
tsconfig.eslint.json
.eslintrc.js