Skip to content

fix: set svelteFeatures.runes to true by default for Svelte 5 #538

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

Merged
merged 4 commits into from
Jun 17, 2024
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/brave-penguins-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-eslint-parser": patch
---

fix: Set `svelteFeatures.runes` to `true` by default for Svelte 5
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,11 @@ export default [
svelteFeatures: {
/* -- Experimental Svelte Features -- */
/* It may be changed or removed in minor versions without notice. */
// If true, it will analyze Runes.
// By default, it will try to read `compilerOptions.runes` from `svelte.config.js`.
// However, note that if `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `false`.
runes: false,
// This option is for Svelte 5. The default value is `true`.
// If `false`, ESLint will not recognize rune symbols.
// If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`.
// If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`.
runes: true,
/* -- Experimental Svelte Features -- */
/* It may be changed or removed in minor versions without notice. */
// Whether to parse the `generics` attribute.
Expand All @@ -311,10 +312,11 @@ For example in `.eslintrc.*`:
"svelteFeatures": {
/* -- Experimental Svelte Features -- */
/* It may be changed or removed in minor versions without notice. */
// If true, it will analyze Runes.
// By default, it will try to read `compilerOptions.runes` from `svelte.config.js`.
// However, note that if the file cannot be parsed by static analysis, it will behave as false.
"runes": false,
// This option is for Svelte 5. The default value is `true`.
// If `false`, ESLint will not recognize rune symbols.
// If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`.
// If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`.
"runes": true,
/* -- Experimental Svelte Features -- */
/* It may be changed or removed in minor versions without notice. */
// Whether to parse the `generics` attribute.
Expand All @@ -329,7 +331,8 @@ For example in `.eslintrc.*`:

**_This is an experimental feature. It may be changed or removed in minor versions without notice._**

If you install Svelte v5 and turn on runes (`compilerOptions.runes` in `svelte.config.js` or `parserOptions.svelteFeatures.runes` in ESLint config is `true`), the parser will be able to parse runes, and will also be able to parse `*.js` and `*.ts` files.
If you install Svelte v5 the parser will be able to parse runes, and will also be able to parse `*.js` and `*.ts` files.
If you don't want to use Runes, you may need to configure. Please read [parserOptions.svelteFeatures](#parseroptionssveltefeatures) for more details.

When using this mode in an ESLint configuration, it is recommended to set it per file pattern as below.

Expand Down Expand Up @@ -383,15 +386,13 @@ For example in `.eslintrc.*`:
"parser": "svelte-eslint-parser",
"parserOptions": {
"parser": "...",
"svelteFeatures": { "runes": true },
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 think 95% of users doesn't need to specify this option, so I removed from README.

/* ... */
},
},
{
"files": ["*.svelte.js"],
"parser": "svelte-eslint-parser",
"parserOptions": {
"svelteFeatures": { "runes": true },
/* ... */
},
},
Expand All @@ -400,7 +401,6 @@ For example in `.eslintrc.*`:
"parser": "svelte-eslint-parser",
"parserOptions": {
"parser": "...(ts parser)...",
"svelteFeatures": { "runes": true },
/* ... */
},
},
Expand Down
9 changes: 5 additions & 4 deletions src/parser/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ export type NormalizedParserOptions = {
[key: string]: any;
};
svelteFeatures?: {
// If true, it will analyze Runes.
// By default, it will try to read `compilerOptions.runes` from `svelte.config.js`.
// However, note that if it cannot be resolved due to static analysis, it will behave as false.
runes?: boolean;
/* -- Experimental Svelte Features -- */
// This option is for Svelte 5. The default value is `true`.
// If `false`, ESLint will not recognize rune symbols.
// If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`.
// If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`.
runes?: boolean;
// Whether to parse the `generics` attribute.
// See https://github.com/sveltejs/rfcs/pull/38
experimentalGenerics?: boolean;
Expand Down
5 changes: 3 additions & 2 deletions src/parser/svelte-parse-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ export function isEnableRunes(
if (!svelteVersion.gte(5)) return false;
if (parserOptions.svelteFeatures?.runes != null) {
return Boolean(parserOptions.svelteFeatures.runes);
} else if (svelteConfig?.compilerOptions?.runes != null) {
}
if (svelteConfig?.compilerOptions?.runes != null) {
return Boolean(svelteConfig.compilerOptions.runes);
}
return false;
return true;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is fundamental changes of this PR. If Svelte 5, the parser will recognize runes as default.

}

export function resolveSvelteParseContextForSvelte(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"svelteConfig": {
"runes": false
}
"svelteConfig": {
"compilerOptions": {
"runes": false
}
}
}
Loading