停止在不使用 Typescript 的 vue 组件上应用 typescript-eslint/explicit-module-boundary-types [英] Stop typescript-eslint/explicit-module-boundary-types to be applied on vue component not using Typescript

查看:371
本文介绍了停止在不使用 Typescript 的 vue 组件上应用 typescript-eslint/explicit-module-boundary-types的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using vue and I just updated @typescript-eslint/eslint-plugin": "^3.10.1". My project contains several components. Some of them are using javascript and others typescript.

对于 typescript 组件

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

warning: Missing return type on function (@typescript-eslint/explicit-module-boundary-types)

问题

我怎么能不在 .vue 文件上不使用 <script lang="ts"> 的文件?

Question

How could I not apply this rule on .vue file which are not using <script lang="ts"> ?

推荐答案

因此,此规则的目的是确保导出的模块对外部使用它的任何人都有一个清晰的界面.来自 规则页面,使用 .ts 文件而不是 .vue 文件似乎更有意义,但您可以根据您的项目需求来判断.

So, the purpose of this rule is to ensure exported modules have a clear interface to whomever uses it externally. From the rule page, it seems to make sense to use for .ts files instead of .vue files, but you can judge from your project needs.

对于我的项目,我使用了 建议的overrides 配置:

For my project, I have used the suggested overrides configuration:

{
  "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 对 eslint 捕获的 .vue 文件说 ,只将规则应用于匹配的文件:'have <script lang="ts">'.

Other than that, I don't think you can have filters for saying on the caught .vue files by eslint, only apply the rule on the ones matched by: 'having <script lang="ts">'.

也许你最好使用内联评论 对于这些特定错误.

Maybe you're better off using inline comments for these specifics errors.

编辑

我看到的另一个解决方案可能是在 .eslint.config 文件中手动列出您的文件.

Another solution I see could be to manually list your files on a .eslint.config file.

使用类型感知规则扩展您的 TypeScript linting我收到错误消息,告诉我该文件必须至少包含在提供的项目之一中" 以获取想法.

See Extending your TypeScript linting with Type-Aware Rules and I get errors telling me "The file must be included in at least one of the projects provided" for ideas.

如果您确实想使用类型感知 linting 来 lint 文件:检查您提供给 parserOptions.project 的每个 tsconfigs 的 include 选项 - 您必须确保所有文件都匹配一个 include glob,否则我们的工具将无法找到它.如果您的文件不应该是现有 tsconfigs 之一的一部分(例如,它是存储库本地的脚本/工具),则考虑在您的文件中创建一个新的 tsconfig(我们建议将其命名为 tsconfig.eslint.json)项目根目录在其包含中列出此文件.例如,您可以查看我们在此 repo 中使用的配置:tsconfig.eslint.json.eslintrc.js

If you do want to lint the file with type-aware linting: Check the include option of each of the tsconfigs that you provide to parserOptions.project - you must ensure that all files match an include glob, or else our tooling will not be able to find it. If your file shouldn't be a part of one of your existing tsconfigs (for example, it is a script/tool local to the repo), then consider creating a new tsconfig (we advise calling it tsconfig.eslint.json) in your project root which lists this file in its include. For an example of this, you can check out the configuration we use in this repo: tsconfig.eslint.json .eslintrc.js

这篇关于停止在不使用 Typescript 的 vue 组件上应用 typescript-eslint/explicit-module-boundary-types的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆