-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Handle warning emitted from the Svelte compiler #8558
Comments
I think I'm -1 on providing an API in the compiler for this. The compiler just returns an array of warnings - it's up to the consumer what it wants to do with those warnings. The But also, any of these tools would also need to provide their own handling for this as a fallback anyway even if the compiler provided it, unless they want to bump their peerdep on the compiler as a breaking change. And for v-p-s, it's not really clear to me what it could do that's simpler, unless it removed the |
Thank you for your response quickly! So I updated my opinion. ESlint plugin will add an option to // is-ignore-svelte-compile-warn.js
export default function (warning) {
if (warning.code === 'a11y-distracting-elements') return true;
return false;
} // svelte.config.js
import isIgnore from './is-ignore-svelte-compile-warn';
// based on https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#onwarn
export default defineConfig({
plugins: [
svelte({
onwarn(warning, defaultHandler) {
// don't warn on <marquee> elements, cos they're cool
if (isIgnore(warning)) return;
// handle all other warnings normally
defaultHandler(warning);
}
})
]
}); import isIgnore from './is-ignore-svelte-compile-warn';
// .eslintrc.js
module.exports = {
rules: {
"svelte/valid-compile": [
"error",
{
ignoreWarnings: false,
ignore: isIgnore,
},
],
},
}; |
Something else I just thought of - if we want to use some CJS-ESM mechanism where we serialize the inputs and outputs of the Svelte compiler, we won't be able to pass callbacks to it anyway. It will have to be the consuming project's job to filter the warnings. |
I don't think we need a callback-based API, it would be enough to pass a list of warning codes to ignore. It would be nice indeed to have something for this because currently people have to configure this across many different places (eslint, language tools VS Code, svelte-check, bundler plugin) |
Svelte 5 provides warningFilter for this |
Describe the problem
Now,
vite-plugin-svelte
andsvelte-check
provide their own warning filter.https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#onwarn
https://github.com/sveltejs/language-tools/tree/master/packages/svelte-check
And now, ESLint users requested to filter warnings.
sveltejs/eslint-plugin-svelte#311
If Svelte compiler itself provides a warning filter, these 3 tools don't need to have this and it will be better in terms of maintainability.
Describe the proposed solution
Provide warning filter by Svelte compiler.
Alternatives considered
Implement warning filter by ESLint plugin.
Importance
nice to have
The text was updated successfully, but these errors were encountered: