Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svelte-check: Ignore diagnostics for imported modules #1495

Open
cbartz opened this issue May 25, 2022 · 8 comments · May be fixed by #1506
Open

svelte-check: Ignore diagnostics for imported modules #1495

cbartz opened this issue May 25, 2022 · 8 comments · May be fixed by #1506
Labels
feature request New feature or request

Comments

@cbartz
Copy link

cbartz commented May 25, 2022

Description

We use svelte-check@2.2.6 and Typescript. We also use generated code in our code basis and would like to have the diagnostics for those modules ignored.
We can neither use the --ignore flag nor an exclude setting in the tsconfig.json to solve this issue, because it does not work for modules who get imported by modules which are getting diagnosed.

Proposed solution

Let the diagnostics for modules be ignored/suppressed, also when they get imported by a module which gets diagnosed.
So, e.g. the lines https://github.com/sveltejs/language-tools/blob/master/packages/language-server/src/plugins/PluginHost.ts#L75-L87 implement this feature hard-coded for files under node_modules. It would be nice if this would also work for any file specified by the --ignore flag (or any newly-introduced flag).

Alternatives

No response

Additional Information, eg. Screenshots

No response

@dummdidumm dummdidumm added the feature request New feature or request label May 25, 2022
@dummdidumm
Copy link
Member

I'm a little hesitant to approve this because it would deviate quite a bit from how "vanilla" TypeScript/tsc works, AFAIK you can't ignore certain files by passing a command line option. Maybe we could allow the ignore option to work for Svelte files but not TS files - but that's possibly even more confusing.

If it's about TS/JS errors, you can silence them by adding a // @ts-nocheck comment to the top of the script tag in your Svelte/TS files.

@cbartz
Copy link
Author

cbartz commented May 31, 2022

Thanks for the reply. So for our case, I would like to suppress the diagnostics for generated code (e.g. generated OpenAPI client stubs, which are in effect typescript modules). We use the output of svelte-check in our CI to determine the code quality.

Certainly I could add (or modify the script in the CI to do it) a // @ts-nocheck comment at the top, but it feels a bit hacky, as I consider these files read-only like the modules under node_modules.

Beyond that, svelte-check still delivers hint diagnostics (but no more errors) for files commented with // @ts-nocheck (see also this issue microsoft/TypeScript#47315), which is also a bit annoying because this pollutes the output (especially if running svelte-check manually).

@dummdidumm
Copy link
Member

You can tell svelte-check to not output hints by adding --threshold warning. I don't think that adding // @ts-nocheck is hacky, it's the recommended way by TS to omit typechecking for files you don't want to be checked, which is the case here.

To me it sounds like your use case could be worked around with these two things, so I'm hesitant to merge this feature right now, maybe sleep on it and/or await some more feedback from other people (other people: please post your use cases here!). I get your point though, this is a valid feature request!

@dummdidumm
Copy link
Member

dummdidumm commented Jun 4, 2022

@cbartz what errors exactly appear in the generated code? Are you able to fix these errors or is this impractical (if yes, why)? How do other code bases (TS+X, not necessarily Svelte) deal with this, this problem must have appeared in many other places as well?

@cbartz
Copy link
Author

cbartz commented Jun 7, 2022

@dummdidumm We get a Hint: 'x' is declared but its value is never read. The CI Job inspects the exit code of svelte-check in order to decide if it should fail or not, which means that we can ignore this hint in the CI because the exit code is equal to zero. So, for the use case CI, this is not a huge problem, but nevertheless the CI job log gets polluted.
For local development this is a bit annoying, because the output of svelte-check always shows this hint and we are not able to fix it (we do not want to fix generated code).

@NyxCode
Copy link

NyxCode commented Aug 12, 2022

// @ts-nocheck does not work, at least for me. It seems like there is absolutely no way to silence these hints.

I have reproduced it on Stackblitz. This currently makes svelte-check completely unusable for me, since I have to include a emscripten-generated file, which produces over 500 hints.

In the link above, I tried:

  • Setting the check script to svelte-check --tsconfig ./jsconfig.json --ignore ./src/lib/im-a-generated-file.js
  • Adding // @ts-nocheck to the file
  • Adding "exclude": ["./src/lib/im-a-generated-file.js"] to jsconfig.json
  • Setting checkJs to false in jsconfig.json

None of which worked.

@acarl005
Copy link

acarl005 commented Sep 2, 2022

For me, // @ts-nocheck is disabling errors but not hints for a bundle of PrismJS which I am importing from a vendor directory in my project. It is still printing Hint: This constructor function may be converted to a class declaration.

@stanf0rd
Copy link

stanf0rd commented Sep 7, 2022

The same is for generated grpc-web client. Errors and warnings are suppresed, but not hints — they are still polluting all the logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants