TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Allow ignoring certain TS suggestion-level diagnostic codes

Open jsayol opened this issue 7 years ago • 18 comments

Related to what was discussed in https://github.com/Microsoft/vscode/issues/61326. Would provide more granularity to the settings introduced with https://github.com/Microsoft/vscode/pull/46590.

It might be useful to introduce a new setting to ignore certain suggestion diagnostic codes while still keeping suggestion diagnostics enabled, rather than having to disable them altogether.

What I'm proposing is to introduce 2 new settings, javascript.suggestionActions.ignoredCodes and typescript.suggestionActions.ignoredCodes. These would take a list of suggestion diagnostic codes that the user wants to ignore, given as a string of either comma- or space-separated code numbers.

Example:

{
  // ...

  "typescript.suggestionActions.enabled": true,
  "typescript.suggestionActions.ignoredCodes": "7043, 80006"

  // ...
}

This list would only be checked when a suggestion-level diagnostic is received, so including non-suggestion-level diagnostic codes in the list would have no effect (errors and messages would not be ignored).

jsayol avatar Dec 03 '18 11:12 jsayol

@DanielRosenwasser We can implement the filtering on the VS Code side but should consider if we want a consistent story for TS.

mjbvz avatar Dec 03 '18 19:12 mjbvz

@mjbvz That's actually a better idea, adding those settings as compiler options instead.

The diagnostics setting could be extended to not only support a boolean, but to also accept an object with include and exclude arrays of codes. These 2 should be mutually exclusive, I don't see any situation where it would make sense to have both.

So for example, instead of fully disabling diagnostics as it can be done now, the user could do the following to enable all diagnostics except for some of them:

{
  "compilerOptions": {
    "diagnostics": {
      "exclude": [7043, 80006]
    }
  }
}

Or, similarly, only enable some of the diagnostics:

{
  "compilerOptions": {
    "diagnostics": {
      "include": [80003]
    }
  }
}

If it's decided to go that way, it might be worth assigning string identifiers to the diagnostic codes. Something like this would be much more readable:

{
  "compilerOptions": {
    "diagnostics": {
      "exclude": [
        "better-variable-type-may-be-inferred",
        "may-be-converted-to-async-function"
      ]
    }
  }
}

jsayol avatar Dec 03 '18 20:12 jsayol

@DanielRosenwasser

If it's decided to go that way, it might be worth assigning string identifiers to the diagnostic codes

I still agree with this sentiment~

weswigham avatar Dec 04 '18 18:12 weswigham

may be we can add there a file exclusion for gradual migration (to e.g. strict mode) too? exclude those rules for a certain globbing pattern only.

OneCyrus avatar Dec 05 '18 04:12 OneCyrus

want this feature too, mention that awesome-typescript-loader support this feature with the config item ignoreDiagnostics ,I wish that is was supportted by typescript it self

javaxiu avatar Oct 18 '19 04:10 javaxiu

Please provide a way to set these per file (or at least per file type). Some of the suggestions are great in TS files where they will be transpiled away, but should not be suggested for JS files which still need to run directly in older environments.

michens avatar Jan 27 '20 20:01 michens

Is there any progress with this feature? I would like to remove some VSCode suggestions. I would like an option to remove this: Untitled

orassayag avatar Dec 17 '20 13:12 orassayag

Input from the extension ecosystem: this would help with implementing features where a TypeScript language service plugin wants to allow configuration of ignoring certain errors:

https://github.com/frigus02/typescript-sql-tagged-template-plugin/issues/11#issuecomment-826897937

karlhorky avatar Aug 02 '22 15:08 karlhorky

What is the status?

tomaszs avatar Feb 24 '23 11:02 tomaszs

Something like this would be great: image Ref: https://github.com/typescript-language-server/typescript-language-server#workspacedidchangeconfiguration

wenfangdu avatar Jun 11 '23 04:06 wenfangdu

Still a valid point. Any progress here?

Drag13 avatar Oct 11 '23 07:10 Drag13

Some of these diagnostics appear to impair functionality of VSCode (and presumably other IDEs using ts server) when not using specific libraries. For example, diagnostic 2593,

(Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try npm i --save-dev @types/jest or npm i --save-dev @types/mocha and then add 'jest' or 'mocha' to the types field in your tsconfig.)

disables the normal VSCode import suggestions and removes both describe and it from the "Add all missing imports" action.

This diagnostic code is making the assumption that global types are being injected by a test framework, which is not the case by default on Vitest, and is not actually available when running Jest under ESM or when using the inbuilt Node test runner. This means IDE import actions are partially broken for these cases due to this diagnostic.

me4502 avatar Nov 22 '23 03:11 me4502

I'm don't know enough about the code base to take this through the process of adding a compiler option, which presumably touches protocols, command line, etc. There would also need to be tests to submit it, but the code to actually make this work is extremely short. Here is an implementation:

https://github.com/microsoft/TypeScript/compare/main...derammo:TypeScript:derammo_suppressDiagnostics?expand=1

derammo avatar Dec 04 '23 02:12 derammo

Any status? How can I get rid of 80005: 'require' call may be converted to an import.?

patrickReiis avatar May 22 '24 20:05 patrickReiis

any progress? god?

rootgrandfather avatar Jul 19 '24 09:07 rootgrandfather

For TypeScript diagnostic errors you can use Disable TS Errors extension.

Works well for me, for example (settings.json):

{
  "editor.formatOnSave": true,
  "disableTsErrors.customizations": [
    {
      "code": [
        2304,
        2322,
        2339
      ],
      "severity": "off"
    }
  ]
}

YehudaKremer avatar Aug 14 '24 06:08 YehudaKremer

In editors which use typescript-language-server, this can be disabled with the diagnostics.ignoredCodes option. For example, i use helix and in my ~/.config/helix/languages.toml, i have

[language-server.typescript-language-server]
config.diagnostics.ignoredCodes = [
  80001, # File is a CommonJS module; it may be converted to an ES module
]

forivall avatar Jun 11 '25 20:06 forivall