Léo Coco
Léo Coco

Reputation: 4282

Stop typescript-eslint/explicit-module-boundary-types to be applied on vue component not using 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.

Warning

I have this warning for methods inside non typescript components

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

Question

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

Upvotes: 20

Views: 23925

Answers (1)

Reuel Ribeiro
Reuel Ribeiro

Reputation: 1479

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.

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"]
      }
    }
  ]
}

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.

Edit

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

See Also

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

Upvotes: 24

Related Questions