Skip to content

Commit 78d0f78

Browse files
authored
fix(no-unused-svelte-ignore): ignore reactive-component warnings (#1208)
1 parent e9aec7f commit 78d0f78

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

.changeset/three-turkeys-marry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-svelte": patch
3+
---
4+
5+
fix(no-unused-svelte-ignore): ignore reactive-component warnings

packages/eslint-plugin-svelte/src/rules/no-unused-svelte-ignore.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { getSvelteCompileWarnings } from '../shared/svelte-compile-warns/index.j
22
import { createRule } from '../utils/index.js';
33
import type { IgnoreItem } from '../shared/svelte-compile-warns/ignore-comment.js';
44
import { getSvelteIgnoreItems } from '../shared/svelte-compile-warns/ignore-comment.js';
5+
import { VERSION as SVELTE_VERSION } from 'svelte/compiler';
6+
import semver from 'semver';
57

68
export default createRule('no-unused-svelte-ignore', {
79
meta: {
@@ -46,6 +48,14 @@ export default createRule('no-unused-svelte-ignore', {
4648
}
4749

4850
for (const unused of warnings.unusedIgnores) {
51+
if (unused.code === 'reactive-component' && semver.satisfies(SVELTE_VERSION, '<5')) {
52+
// Svelte v4 `reactive-component` warnings are not emitted
53+
// when we use the `generate: false` compiler option.
54+
// This is probably not the intended behavior of Svelte v4, but it's not going to be fixed,
55+
// so as a workaround we'll ignore the `reactive-component` warnings.
56+
// See https://github.com/sveltejs/eslint-plugin-svelte/issues/1192
57+
continue;
58+
}
4959
context.report({
5060
loc: {
5161
start: sourceCode.getLocFromIndex(unused.range[0]),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script lang="ts">
2+
import { onMount } from 'svelte'
3+
4+
let MyComponent: typeof import('./MyComponent.svelte').default | undefined
5+
onMount(() => {
6+
import('./MyComponent.svelte').then((component) => {
7+
MyComponent = component.default
8+
})
9+
})
10+
</script>
11+
12+
{#if MyComponent}
13+
<!-- svelte-ignore reactive-component -->
14+
<MyComponent />
15+
{/if}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"svelte": "^4"
3+
}

0 commit comments

Comments
 (0)