Skip to content

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

Merged
merged 9 commits into from
Jul 16, 2024

Conversation

dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Jul 4, 2024

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 like onwarn, 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 for onwarn wants, and we could also use that same logic on svelte-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 an onwarn function) if other maintainers think this is a good idea.
We decided to go with a 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

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Jul 4, 2024

🦋 Changeset detected

Latest commit: 085b7f6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

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
@dummdidumm
Copy link
Member Author

Good to go apart from this question: should it be called filterWarning (singular instead of plural), since it's only concerned with one warning at a time?

@Rich-Harris
Copy link
Member

Another idea: warningFilter — in other words filter is a noun rather than a verb, and warning is the qualifier rather than the subject. That way we side-step the question altogether

@@ -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
Copy link
Member

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.

Suggested change
* @param {{ filename?: string, rootDir?: string, filterWarning?: CompileOptions['filterWarning'] }} options
* @param {{ filename?: string, rootDir?: string, filterWarning: CompileOptions['filterWarning'] }} options

Copy link
Member Author

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;
Copy link
Member

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 &&

Suggested change
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (filter_warning && !filter_warning(warning)) return;
if (!filter_warning(warning)) return;

@Rich-Harris
Copy link
Member

Oops, looks like we need to reset warningFilter before we validate options, because we need to call it during validation. Fix incoming

@Rich-Harris Rich-Harris merged commit d9569d0 into main Jul 16, 2024
9 checks passed
@Rich-Harris Rich-Harris deleted the warning-ignore-option branch July 16, 2024 15:41
trueadm pushed a commit that referenced this pull request Jul 16, 2024
* 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>
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

Successfully merging this pull request may close these issues.

Allowing for modes on a11y
3 participants