停止将 typescript-eslint/explicit-module-boundary-types 应用于不使用 Typescript 的 vue 组件

2024-02-08

我在用着vue我刚刚更新了@typescript-eslint/eslint-plugin": "^3.10.1"。我的项目包含几个组件。其中一些正在使用javascript和别的typescript.

Warning

我对里面的方法有这个警告non typescript成分

警告:函数缺少返回类型(@typescript-eslint/explicit-module-boundary-types)

Question

我怎么能不应用这个规则.vue不使用的文件<script lang="ts"> ?


因此,此规则的目的是确保导出的模块对外部使用它的任何人都有清晰的接口。来自规则页面 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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

停止将 typescript-eslint/explicit-module-boundary-types 应用于不使用 Typescript 的 vue 组件 的相关文章

随机推荐