-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: add ability to ignore warnings through compiler option #12296
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
Conversation
🦋 Changeset detectedLatest commit: 085b7f6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Some people want to disable certain warnings for their whole application without having to add svelte-ignore comments everywhere. This new option makes that possible. closes #9188 part of sveltejs/language-tools#650
538d30a
to
281debf
Compare
Good to go apart from this question: should it be called |
Another idea: |
@@ -50,7 +53,7 @@ export function pop_ignore() { | |||
|
|||
/** | |||
* @param {string} _source | |||
* @param {{ filename?: string, rootDir?: string }} options | |||
* @param {{ filename?: string, rootDir?: string, filterWarning?: CompileOptions['filterWarning'] }} options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if this was required? The parse
API would need to supply a default () => true
option, but could also take an option which would be useful. The other place reset
is called is in migrate
, where we probably want to use () => false
since there's not a lot that can be done about warnings there.
* @param {{ filename?: string, rootDir?: string, filterWarning?: CompileOptions['filterWarning'] }} options | |
* @param {{ filename?: string, rootDir?: string, filterWarning: CompileOptions['filterWarning'] }} options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other places don't care about warnings (there's nothing done with them), and we need to call reset
anyway at which point any warnings are deleted, so not sure it's worth it.
We can definitely fall back to () => true
in state.js
though to avoid the dance in compile_warnings.js
); | ||
|
||
if (filter_warning && !filter_warning(warning)) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make it required, we can get rid of filter_warning &&
if (filter_warning && !filter_warning(warning)) return; | |
if (!filter_warning(warning)) return; |
|
||
const warning = new InternalCompileWarning(code, message, node && node.start !== undefined ? [node.start, node.end ?? node.start] : undefined); | ||
|
||
if (filter_warning && !filter_warning(warning)) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (filter_warning && !filter_warning(warning)) return; | |
if (!filter_warning(warning)) return; |
Oops, looks like we need to reset |
* feat: add ability to ignore warnings through compiler option Some people want to disable certain warnings for their whole application without having to add svelte-ignore comments everywhere. This new option makes that possible. closes #9188 part of sveltejs/language-tools#650 * make it a function * singular * warningFilter * make internal filter non-nullable * Update .changeset/little-seals-reflect.md * filter_warning -> warning_filter, for symmetry with public option * fix --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>
Some people want to disable certain warnings for their whole application without having to add svelte-ignore comments everywhere. This new option makes that possible.
closes #9188
part of sveltejs/language-tools#650
I briefly thought about making it a function likeWe decided to go with aonwarn
, which has more flexibility, but I think in this case it's better to be simple and just pass a list of strings.I also thought about whether or not we should allow something like
a11y_*
, which means "everything starting with a11y_ is ignored". This would give the same flexibility someone foronwarn
wants, and we could also use that same logic onsvelte-ignore
comments (e.g. you can do<!-- svelte-ignore a11y_* -->
to ignore multiple a11y warnings at once). I would be open to adding this capability (more than having anonwarn
function) if other maintainers think this is a good idea.warning => boolean
function. Provides more flexibility, and since the warning contains the filename you could also filter based on where the component is.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint