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

Config file for svelte-check #2559

Closed
ptrxyz opened this issue Nov 4, 2024 · 4 comments
Closed

Config file for svelte-check #2559

ptrxyz opened this issue Nov 4, 2024 · 4 comments

Comments

@ptrxyz
Copy link

ptrxyz commented Nov 4, 2024

Description

Svelte check offers a few settings like settings a tsconfig file or ignoring error messages. Currently it is only possible to set those using the command line switches.

I suggest that svelte-check also looks for a config file in the workspace root for the following reason:
svelte-check is run by several tools, i.e. on the VSCode extension and the language server or ESlint when using the svelte/valid-compile rules. In addition, people use svelte-check in CI/CD workflows and run it manually using npx/npm or via scripts in the package.json.

If I would like certain warnings to always be disabled, I have to configure each tool individually -- this causes quite some overhead and sometimes is not even possible (i.e. ESlint's rule does not provide a way to ignore only some warnings, but only either ignore everything or nothing).

Proposed solution

I suggest that svelte-check also looks for a file, let's say svelte-check.config.json or maybe a setting in svelte.config.[cjs|mjs|ts] that makes it possible to enable certain commonly used settings.
something like this would work:

{
  "tsconfig": "./tsconfig.json"
  "compiler-warnings": {
    "a11y-label": "ignore"
  },
  ...
}

The schema could follow the schema from the sv CLI tool and we could load the before any manually passed config options are evaluated so that those take priority for backwards compatibility.

Loading order would be: default values --> load file if present --> overwrite with options manually passed to svelte-check.

Alternatives

Maybe we could make the most important settings available through ENV variables like so:

SVELTE_CHECK_TSCONFIG="./tsconfig.json"
SVELTE_CHECK_COMPILER_WARNINGS="foo:ignore,bar:ignore"
SVELTE_CHECK_FAIL_ON_WARNINGS="true"

Additional Information, eg. Screenshots

Just to outline the extend of the issue in a simple case:
To disable a single warning, you currently would do this:

  • add a filter in your svelte.config.js
		warningFilter(w) {
			if (w.code.includes('foo')) return false
			if (w.code.includes('bar')) return false
			return true
		},
  • edit package.json > scripts > check to include --compiler-warnings "foo:ignore,bar:ignore"
  • remember when you run sv check manually, to also add all your rules: --compiler-warnings "foo:ignore,bar:ignore"
  • open VS Code extensions -> workspace settings -> compiler options; edit all the warnings one-by-one.
    image
  • if you have separate CI/CD configs, rinse and repeat...
@jasonlyu123
Copy link
Member

warningFilter is meant to be a way to unified suppress warnings. And svelte-check also supports this. You don't need to use compiler-warnings if you already filter it out in warningFIilter. For ESLint, ESLint doesn't run svelte-check under the hood. The warning is from the compiler itself. ESLint-plugin-svelte doesn't seem to support warningFIlter so you might have to open an issue there. But It does support the onwarn for vite-plugin-svelte with some extra config so it should be possible for eslint to support it.

As for --tsconfig and --fail-on-warnings, these are not available in the language server so there isn't anything to reuse.

@ptrxyz
Copy link
Author

ptrxyz commented Nov 4, 2024

Ok, so what I understand is that svelte-check (the CLI) already uses warningFilter and thus editing package.json and adding the params on the CLI is not needed. Same is true for the VSCode extension.

ESLint does not use the SvelteCheck backend (

) and thus needs it's own configuration.

The other options of svelte-check are not relevant to other tools and it would thus not make sense to be put into a shared config file.

This would still not exactly be a replacement to what I suggested since warningFilter can not easily turned off (i.e. one might want it to be turned off by default, but turned one for a thorough run before building for release), but I guess you can always make that work using JS code.

So, if I got it all correct, I guess I'll ask the eslint-plugin-svelte team to consider evaluating the warningFilter setting.

@ptrxyz
Copy link
Author

ptrxyz commented Nov 4, 2024

I opened sveltejs/eslint-plugin-svelte#905

@dummdidumm
Copy link
Member

You're correct - eslint is the only one left to support this compiler option, therefore closing

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

No branches or pull requests

3 participants