Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/three-turkeys-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-svelte": patch
---

fix(no-unused-svelte-ignore): ignore reactive-component warnings
10 changes: 10 additions & 0 deletions packages/eslint-plugin-svelte/src/rules/no-unused-svelte-ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { getSvelteCompileWarnings } from '../shared/svelte-compile-warns/index.j
import { createRule } from '../utils/index.js';
import type { IgnoreItem } from '../shared/svelte-compile-warns/ignore-comment.js';
import { getSvelteIgnoreItems } from '../shared/svelte-compile-warns/ignore-comment.js';
import { VERSION as SVELTE_VERSION } from 'svelte/compiler';
import semver from 'semver';

export default createRule('no-unused-svelte-ignore', {
meta: {
Expand Down Expand Up @@ -46,6 +48,14 @@ export default createRule('no-unused-svelte-ignore', {
}

for (const unused of warnings.unusedIgnores) {
if (unused.code === 'reactive-component' && semver.satisfies(SVELTE_VERSION, '<5')) {
// Svelte v4 `reactive-component` warnings are not emitted
// when we use the `generate: false` compiler option.
// This is probably not the intended behavior of Svelte v4, but it's not going to be fixed,
// so as a workaround we'll ignore the `reactive-component` warnings.
// See https://github.com/sveltejs/eslint-plugin-svelte/issues/1192
continue;
}
context.report({
loc: {
start: sourceCode.getLocFromIndex(unused.range[0]),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script lang="ts">
import { onMount } from 'svelte'

let MyComponent: typeof import('./MyComponent.svelte').default | undefined
onMount(() => {
import('./MyComponent.svelte').then((component) => {
MyComponent = component.default
})
})
</script>

{#if MyComponent}
<!-- svelte-ignore reactive-component -->
<MyComponent />
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"svelte": "^4"
}
Loading