Language-tools: How can we disable svelte warnings? (a11y, etc)

Created on 2 Nov 2020  ·  12Comments  ·  Source: sveltejs/language-tools

These warnings often do more harm than good and pollute our console real estate.
It's not acceptable to litter the code with <!-- svelte-ignore a11y-no-onchange --> etc.

We can usually filter these in the rollup.config but svelte-check won't pick that.

What's the best way to filter these:

  • in the console when using svelte-check --watch
  • in VScode (without having to tell everyone to manually add tons of entries in their IDE preferences)

Is it time perhaps to introduce a config file?

question

Most helpful comment

nope, I don't use lsp-mode. I use neovim's builtin LSP and it can pass some options to the LSP. Here's how it's done.

image

I don't know how lsp-mode handle this option. I did a quick reading from its wiki and I think it's possible to do. It can pass some options to Lua LSP for example. https://emacs-lsp.github.io/lsp-mode/page/lsp-lua-language-server/

All 12 comments

You can use the --compiler-warnings option, for example --compiler-warnings "css-unused-selector:ignore,unused-export-let:ignore" will filter out all css-unused-selector and unused-export-let warnings. See the svelte-check readme for more info.
About the VS Code thing: You can always add a workspace settings json to your repo which all users will inherit. I'm hesitant to put this inside svelte.config.js since there's no official agreement in which direction this config file will go so I don't want to add things in a rush there.

Thanks.

The --compiler-warnings would do the job for the cli, yes. As for the workspace settings json, is that something you often use in addition to a .editorconfig?

Well, if you all use VS Code and you agree on certain settings, I would certainly use it - it's a kind of config file, too, after all. We do it in one of our projects right now.

Does this apply to the language server as well? Or only to svelte-check? I tried running the language server as svelteserver --stdio --compiler-warnings a11y-autofocus:ignore,a11y-no-onchange:ignore, however the language server is still producing warnings:

image

This is in Emacs using lsp-mode.

This only applies to vscode and svelte-check. How do other IDEs integrate with the language server? The language server expects a config object (structure as in the vscode extension readme) on startup during the initialisation command according to the language server protocol.

Gotcha. All full-featured language server clients, including lsp-mode under Emacs, have support for passing a configuration over JSONRPC to the server. Now that I understand where this is intended to be configured, it should be straightforward to enhance the Svelte module in lsp-mode to hook that configuration key to a convenient user option. I will open an issue against lsp-mode accordingly.

It would probably be worth mentioning this explicitly in the README: "Configuration of the language server happens over the LSP protocol by passing a configuration object; your LSP client should have a way of setting the configuration object for a server. Here is a link to the spec for the configuration that is supported [...]"

It also might be worth actually parsing the command-line options and/or throwing an error when any are passed; it was not clear to me whether command-line options were supported, since --help did not function as expected.

Thanks for your help.

@elianiva in a recent issue you mentioned that you also run the LSP directly and were able to configure some setting - any chance you use the same LSP-mode @raxod502 is talking about so might be able to help?

nope, I don't use lsp-mode. I use neovim's builtin LSP and it can pass some options to the LSP. Here's how it's done.

image

I don't know how lsp-mode handle this option. I did a quick reading from its wiki and I think it's possible to do. It can pass some options to Lua LSP for example. https://emacs-lsp.github.io/lsp-mode/page/lsp-lua-language-server/

Yes, this is fully supported by lsp-mode, and in a fairly advanced way: each configuration key can be easily mapped to a separately documented user option. Here is an example for gopls: https://github.com/emacs-lsp/lsp-mode/blob/0349a1cc0976829fab8f73ecc033252be31a7cf6/clients/lsp-go.el#L215-L221

@dummdidumm I too decided to try neovim-lsp, and it works brilliantly even with zip-packed yarn 2 packages, thanks to overridable cmd option:

lspconfig.tsserver.setup{
  cmd = { "yarn", "typescript-language-server", "--stdio" };
  on_attach = on_attach;
}

lspconfig.svelte.setup{
  cmd = { "yarn", "svelteserver", "--stdio" };
  on_attach = on_attach;
  settings = {
    svelte = {
      compilerWarnings = {
        ["a11y-no-onchange"] = "ignore"; -- <<< This doesn't work, svelte still spams me with this warning
      }
    }
  }
}

language-server's readme lacks configuration options, which I've found in svelte-vscode package. :thinking:
More editors make their lsp implementations, so it is better to have options in the language-server's readme too.
Do you want me to make a readme PR that clarifies configuration process for neovim-lsp and makes a link to the lsp options which are described in svelte-vscode package?

For some reason, when parsing svelte.config.js, language-server ignores onwarn, but uses preprocess. Is that intended?
I feel like it is more straightforward to configure that from svelte.config.js.
Can't seem to get compilerWarnings ignores to work by passing options from neovim-lsp. :disappointed:

const sveltePreprocess = require('svelte-preprocess');

module.exports = {
  preprocess: sveltePreprocess(),
  onwarn: (warning, handler) => {
    if (warning.code === 'a11y-no-onchange') return;
    handler(warning);
  },
};

@non25 this should work because it's svelte.plugin.svelte.compilerWarnings, not svelte.compilerWarnings

lspconfig.svelte.setup{
  cmd = { "yarn", "svelteserver", "--stdio" };
  on_attach = on_attach;
  settings = {
    svelte = {
      plugin = {
        svelte = {
          compilerWarnings = {
            ["a11y-no-onchange"] = "ignore"
          }
        }
      }
    }
  }
}

How do I suppress a waning when using e.g. "sapper dev" command? I don't see any "compiler-warnings" option at all. Thank you.

Was this page helpful?
0 / 5 - 0 ratings