Skip to content
Open
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/late-waves-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': patch
---

fix(valid-compile): use compiler options if provided
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ function getWarningsFromCode(
} {
try {
const result = compiler.compile(code, {
...context.sourceCode.parserServices.svelteParseContext?.svelteConfig?.compilerOptions,
Copy link
Member

Choose a reason for hiding this comment

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

To avoid unintended behavior, can you please pass only the necessary options?

Since generate: false is different from the compiler used by the user, I think it is highly likely that the user's defined compilerOptions cannot be used as is.

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you explain this in a bit more detail?
If generate: false is specified, the Svelte compiler just skips the transform phase, so I don’t think it would be a problem to overwrite the user’s settings for generate. Also, options that are only used in the transform phase would simply go unused, so I don’t think they would have any side effects.

https://github.com/sveltejs/svelte/blob/main/packages/svelte/src/compiler/phases/3-transform/index.js#L20-L30

Copy link
Member

Choose a reason for hiding this comment

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

Compiler options have many properties, and I don't think we understand how they affect linting. Also, I don't think users set compiler options with linting in mind.
Therefore, I think it's better to avoid passing them directly.
I think it's better to pass only the necessary properties that we understand.
https://svelte.dev/docs/svelte/svelte-compiler#CompileOptions
https://svelte.dev/docs/svelte/svelte-compiler#ModuleCompileOptions

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we understand how they affect linting

I believe I understand your concern. I have no objection to making the fix.
However, in this particular case, do we really need to worry about the affect? Wouldn’t it be fine to simply compile exactly as the user specified and then display whatever warnings are generated to the user? If something strange happens, wouldn’t that just mean the user’s configuration was wrong?

Copy link
Member

Choose a reason for hiding this comment

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

The reason I'm concerned may be because I don't know the internals of the compiler, so I don't have the information to not worry 😓

generate: false,
...(isCustomElement(context.sourceCode.ast) ? { customElement: true } : {})
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"languageOptions": {
"parserOptions": {
"svelteConfig": {
"compilerOptions": {
"runes": true
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- message: >-
`count` is updated, but is not declared with `$state(...)`. Changing its
value will not correctly trigger updates

https://svelte.dev/e/non_reactive_update(non_reactive_update)
line: 2
column: 6
suggestions: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script lang="ts">
let count = 0;
function increment() {
count += 1;
}
</script>

{count}<br />
<button onclick={increment} type="button">Increment</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"svelte": ">=5.0.0"
}
Loading