Closed ota-meshi closed 2 weeks ago
Latest commit: baf724add98bd1672d44d88eb4c7c500bf0f285a
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
src/parser/globals.ts | 7 | 8 | 87.5% | ||
src/svelte-config/parser.ts | 78 | 80 | 97.5% | ||
<!-- | Total: | 160 | 163 | 98.16% | --> |
Totals | |
---|---|
Change from base Build 9529150497: | 0.1% |
Covered Lines: | 2949 |
Relevant Lines: | 3131 |
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
src/parser/globals.ts | 7 | 8 | 87.5% | ||
src/svelte-config/parser.ts | 78 | 80 | 97.5% | ||
<!-- | Total: | 160 | 163 | 98.16% | --> |
Totals | |
---|---|
Change from base Build 9529150497: | 0.1% |
Covered Lines: | 2949 |
Relevant Lines: | 3131 |
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
src/parser/globals.ts | 7 | 8 | 87.5% | ||
src/svelte-config/parser.ts | 78 | 80 | 97.5% | ||
<!-- | Total: | 160 | 163 | 98.16% | --> |
Totals | |
---|---|
Change from base Build 9529150497: | 0.1% |
Covered Lines: | 2949 |
Relevant Lines: | 3131 |
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
src/parser/globals.ts | 7 | 8 | 87.5% | ||
src/scope/index.ts | 5 | 7 | 71.43% | ||
src/svelte-config/parser.ts | 116 | 132 | 87.88% | ||
<!-- | Total: | 196 | 215 | 91.16% | --> |
Totals | |
---|---|
Change from base Build 9529150497: | -0.5% |
Covered Lines: | 2985 |
Relevant Lines: | 3183 |
I realized that it would be better to have svelte.config.js
specified in eslint.config.js
rather than statically analyzing svelte.config.js
. I will make that change.
Done
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
src/parser/globals.ts | 7 | 8 | 87.5% | ||
src/scope/index.ts | 5 | 7 | 71.43% | ||
src/svelte-config/parser.ts | 125 | 151 | 82.78% | ||
<!-- | Total: | 207 | 236 | 87.71% | --> |
Totals | |
---|---|
Change from base Build 9529150497: | -1.0% |
Covered Lines: | 2996 |
Relevant Lines: | 3204 |
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
src/parser/globals.ts | 7 | 8 | 87.5% | ||
src/scope/index.ts | 5 | 7 | 71.43% | ||
src/svelte-config/parser.ts | 125 | 151 | 82.78% | ||
<!-- | Total: | 207 | 236 | 87.71% | --> |
Totals | |
---|---|
Change from base Build 9529150497: | -1.0% |
Covered Lines: | 2996 |
Relevant Lines: | 3204 |
I have a question.
Both runes mode and legacy mode can use store right? Can you tell me more details why this PR can solve below?
Added a new option parserOptions.svelteConfig to specify svelte.config.js.
This is just my opinion but, in 99% of cases, compilerOptions.runs
is defined statically in svelte.config.js
.
So I think it's enough to parse svelte.config.js
statically by default.
And we will use svelteFeatures.runes
only if the value is explicitly specified in eslint config.
Hmm... I guess I misunderstood something. This PR doesn't solve https://github.com/sveltejs/eslint-plugin-svelte/issues/652. I thought that telling the compiler the runes mode correctly would solve the problem, but it didn't :sweat:
This is just my opinion but, in 99% of cases, compilerOptions.runs is defined statically in svelte.config.js. So I think it's enough to parse svelte.config.js statically by default. And we will use svelteFeatures.runes only if the value is explicitly specified in eslint config.
You are right about the compilerOptions.runs
.
However, we think that in the future we might want to access more than just compilerOptions.runs
, so I thought it made sense to add this option now.
For example, the following issue in eslint-plugin-svelte
can be easily resolved if we have access to onwarn
.
https://github.com/sveltejs/eslint-plugin-svelte/issues/311
For example, we can get the correct routes
information even without the following settings:
https://sveltejs.github.io/eslint-plugin-svelte/user-guide/#settings-svelte-kit
Currently, the parser does not use any information other than compilerOptions.runs
. However, I think that in the future it may.
Also we can also use it from parserServices
to share svelte.config.js
information with eslint-plugin rules.
However, we think that in the future we might want to access more than just compilerOptions.runs, so I thought it made sense to add this option now.
Agreed!
How about mimic the logic with vite-plugin-svelte
?
https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#config-file
As default, user don't need to configure parserOptions.svelteConfig
but automatically read the file.
If user use special file name, then user can configure parserOptions.svelteConfig
or configure svelteFeatures .xxx
as inline option.
It would be convenient for users if fewer settings could be made. And svelte users may easier to understand if there are similar rules across the Svelte ecosystem.
As default, user don't need to configure parserOptions.svelteConfig but automatically read the file.
Unfortunately, currently the eslint custom parser cannot load ESMs because it needs to run synchronously, so svelte.config.js
cannot be loaded inside the parser.
Ah I forgot thisπ .
@baseballyama With this change, we might still be missing some features π
I have a question. Will the Svelte core compiler automatically parse runes as runes when they are used, even without compilerOptions.runes
?
If so, this parser needs to be handled the same way.
Ahh, yeah, you are right.
If there is rune symbol in .svelte
/ .svelte.js
file, compiler will automatically enable rune mode for the component.
If compilerOptions.runes
is true, apply rune mode compulsorily. (So we can not use export let xxx
anymore.)
If compilerOptions.runes
is false, the compiler doesn't use runes. (So if there is $derived
or some runes, $derived
will be behave as normal variable.)
I'm fixing.
related to #423
This PR changes the parser to allow opt-in/out of Rune parsing. (However, it requires Svelte v5.)
The main changes are:
svelteFeatures.runes
to control whether runes are parsed.parserOptions.svelteConfig
to specifysvelte.config.js
. If not specified, some config will be statically parsed from thesvelte.config.js
file.svelteFeatures.runes
, it will read thecompilerOptions.runes
insvelte.config.js
.<svelte:options runes={...}>
is present, it determines whether to prioritize them and parse Runes.svelteParseContext
, to make that information available to the eslint-plugin.I think the next issue can be solved by telling the compiler whether it should parse in rune mode.https://github.com/sveltejs/eslint-plugin-svelte/issues/652