eslint-plugin-svelte: svelte-ignore reactive-component not working
Before You File a Bug Report Please Confirm You Have Done The Following…
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
What version of ESLint are you using?
9.24.0
What version of eslint-plugin-svelte are you using?
3.5.1
What did you do?
Configuration
Default from sv create:
import js from '@eslint/js';
import { includeIgnoreFile } from '@eslint/compat';
import svelte from 'eslint-plugin-svelte';
import globals from 'globals';
import { fileURLToPath } from 'node:url';
import ts from 'typescript-eslint';
import svelteConfig from './svelte.config.js';
const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url));
export default ts.config(
includeIgnoreFile(gitignorePath),
js.configs.recommended,
...ts.configs.recommended,
...svelte.configs.recommended,
{
languageOptions: {
globals: { ...globals.browser, ...globals.node }
},
rules: { // typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.
// see: https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
"no-undef": 'off' }
},
{
files: [
'**/*.svelte',
'**/*.svelte.ts',
'**/*.svelte.js'
],
ignores: ['eslint.config.js', 'svelte.config.js'],
languageOptions: {
parserOptions: {
projectService: true,
extraFileExtensions: ['.svelte'],
parser: ts.parser,
svelteConfig
}
}
}
);
<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}
What did you expect to happen?
No errors, because this comment works to successfully ignore the reactive-component runtime warning
What actually happened?
Gives this error:
svelte-ignore comment is used, but not warned svelte/no-unused-svelte-ignore
Link to GitHub Repo with Minimal Reproducible Example
https://github.com/probablykasper/svelte-ignore-reactive-component-bug
Additional comments
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (16 by maintainers)
I think
reactive-componentis probably the only special warning emitted in the render (transform) phase in Svelte 4.I think it would make sense for us to change the
svelte/no-unused-svelte-ignorerule to ignore onlyreactive-component.We might be able to lint correctly by removing
generate: false, but I think that’s probably not what Svelte core intends.The documentation says that
generate: falseis useful for tooling.https://svelte.dev/docs/svelte/svelte-compiler#ModuleCompileOptions
I think I probably used
generate: falsebased on the code ineslint-plugin-svelte3.https://github.com/sveltejs/eslint-plugin-svelte3/blob/92671bee83b1d38979e1b0f2897a987cbd61b808/src/preprocess.js#L245
Shouldn’t we use
generate: false? 🤔