Skip to content

Commit 35d80a5

Browse files
authored
feat: support warningFilter in valid-compile rule (#984)
1 parent faf90ef commit 35d80a5

File tree

18 files changed

+87
-8
lines changed

18 files changed

+87
-8
lines changed

.changeset/great-turkeys-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': minor
3+
---
4+
5+
feat: support `warningFilter` in `valid-compile` rule

docs/rules/valid-compile.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Note that we exclude reports for some checks, such as `missing-declaration`, and
3535

3636
### Using `svelte.config.js`
3737

38-
If you want to suppress messages using [`onwarn` like `vite-plugin-svelte`](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#onwarn), Use `eslint.config.js` and specify the information in `svelte.config.js` in your parser configuration.
38+
If you want to suppress messages using [`warningFilter`](https://svelte.dev/docs/svelte/svelte-compiler#ModuleCompileOptions) or `onwarn` like [`vite-plugin-svelte`](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#onwarn), Use `eslint.config.js` and specify the information in `svelte.config.js` in your parser configuration.
3939

4040
```js
4141
import svelteConfig from './svelte.config.js';
@@ -54,9 +54,26 @@ export default [
5454

5555
See also [User Guide > Specify `svelte.config.js`](../user-guide.md#specify-svelte-config-js)
5656

57+
#### warningFilter
58+
59+
This rule can use [`warningFilter`](https://svelte.dev/docs/svelte/svelte-compiler#ModuleCompileOptions).
60+
61+
Example:
62+
63+
```js
64+
// svelte.config.js
65+
export default {
66+
warningFilter: (warning) => {
67+
if (warning.code === 'a11y-distracting-elements') return false;
68+
if (warning.code === 'a11y_distracting_elements') return false; // for Svelte v5
69+
return true;
70+
}
71+
};
72+
```
73+
5774
#### onwarn
5875

59-
This rule can use [`onwarn` like `vite-plugin-svelte`](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#onwarn).
76+
This rule can use `onwarn` like [`vite-plugin-svelte`](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#onwarn).
6077

6178
Example:
6279

packages/eslint-plugin-svelte/src/rules/valid-compile.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,22 @@ export default createRule('valid-compile', {
5555
if (!sourceCode.parserServices.isSvelte) {
5656
return {};
5757
}
58-
const onwarn = sourceCode.parserServices.svelteParseContext?.svelteConfig?.onwarn;
58+
const { onwarn, warningFilter } =
59+
sourceCode.parserServices.svelteParseContext?.svelteConfig ?? {};
5960

60-
const transform: (warning: Warning) => Warning | null = onwarn
61+
const transform: (warning: Warning) => Warning | null = warningFilter
6162
? (warning) => {
6263
if (!warning.code) return warning;
63-
let result: Warning | null = null;
64-
onwarn(warning, (reportWarn) => (result = reportWarn));
65-
return result;
64+
return warningFilter(warning) ? warning : null;
6665
}
67-
: (warning) => warning;
66+
: onwarn
67+
? (warning) => {
68+
if (!warning.code) return warning;
69+
let result: Warning | null = null;
70+
onwarn(warning, (reportWarn) => (result = reportWarn));
71+
return result;
72+
}
73+
: (warning) => warning;
6874

6975
const ignoreWarnings = Boolean(context.options[0]?.ignoreWarnings);
7076
const globalStyleRanges: [Position, Position][] = [];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy