Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: makes it optional whether to parse runes. #536

Merged
merged 6 commits into from
Jun 17, 2024
Merged

feat: makes it optional whether to parse runes. #536

merged 6 commits into from
Jun 17, 2024

Conversation

ota-meshi
Copy link
Member

@ota-meshi ota-meshi commented Jun 16, 2024

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:

  • Added a new option svelteFeatures.runes to control whether runes are parsed.
  • Added a new option parserOptions.svelteConfig to specify svelte.config.js.
    If not specified, some config will be statically parsed from the svelte.config.js file.
  • If there is no option in svelteFeatures.runes, it will read the compilerOptions.runes in svelte.config.js.
  • If <svelte:options runes={...}> is present, it determines whether to prioritize them and parse Runes.
  • Change the parser service to provide svelteParseContext, to make that information available to the eslint-plugin.

Copy link

changeset-bot bot commented Jun 16, 2024

🦋 Changeset detected

Latest commit: baf724a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte-eslint-parser Minor

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

@coveralls
Copy link

coveralls commented Jun 16, 2024

Pull Request Test Coverage Report for Build 9534250043

Details

  • 160 of 163 (98.16%) changed or added relevant lines in 10 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 91.501%

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%
Totals Coverage Status
Change from base Build 9529150497: 0.1%
Covered Lines: 2949
Relevant Lines: 3131

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 16, 2024

Pull Request Test Coverage Report for Build 9534267800

Details

  • 160 of 163 (98.16%) changed or added relevant lines in 10 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 91.501%

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%
Totals Coverage Status
Change from base Build 9529150497: 0.1%
Covered Lines: 2949
Relevant Lines: 3131

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 16, 2024

Pull Request Test Coverage Report for Build 9534824834

Details

  • 160 of 163 (98.16%) changed or added relevant lines in 10 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 91.482%

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%
Totals Coverage Status
Change from base Build 9529150497: 0.1%
Covered Lines: 2949
Relevant Lines: 3131

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9540091489

Details

  • 196 of 215 (91.16%) changed or added relevant lines in 10 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.5%) to 90.864%

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%
Totals Coverage Status
Change from base Build 9529150497: -0.5%
Covered Lines: 2985
Relevant Lines: 3183

💛 - Coveralls

@ota-meshi ota-meshi marked this pull request as draft June 17, 2024 00:48
@ota-meshi
Copy link
Member Author

ota-meshi commented Jun 17, 2024

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

@coveralls
Copy link

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9541551900

Details

  • 207 of 236 (87.71%) changed or added relevant lines in 10 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.0%) to 90.411%

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%
Totals Coverage Status
Change from base Build 9529150497: -1.0%
Covered Lines: 2996
Relevant Lines: 3204

💛 - Coveralls

@ota-meshi ota-meshi marked this pull request as ready for review June 17, 2024 03:39
@coveralls
Copy link

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9541685261

Details

  • 207 of 236 (87.71%) changed or added relevant lines in 10 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.0%) to 90.411%

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%
Totals Coverage Status
Change from base Build 9529150497: -1.0%
Covered Lines: 2996
Relevant Lines: 3204

💛 - Coveralls

@baseballyama
Copy link
Member

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.

@ota-meshi
Copy link
Member Author

Hmm... I guess I misunderstood something.
This PR doesn't solve sveltejs/eslint-plugin-svelte#652.
I thought that telling the compiler the runes mode correctly would solve the problem, but it didn't 😓

@ota-meshi
Copy link
Member Author

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.

sveltejs/eslint-plugin-svelte#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.

@baseballyama
Copy link
Member

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.

@ota-meshi
Copy link
Member Author

ota-meshi commented Jun 17, 2024

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.

See eslint/eslint#15475

@baseballyama
Copy link
Member

Ah I forgot this😅.

Copy link
Member

@baseballyama baseballyama left a comment

Choose a reason for hiding this comment

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

Nice!

@ota-meshi ota-meshi merged commit 1a9ef3d into main Jun 17, 2024
13 checks passed
@ota-meshi ota-meshi deleted the runes-opt branch June 17, 2024 11:09
@ota-meshi
Copy link
Member Author

ota-meshi commented Jun 17, 2024

@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.

@baseballyama
Copy link
Member

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.)

@baseballyama
Copy link
Member

I'm fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants