Skip to content

Commit

Permalink
fix: set svelteFeatures.runes to true by default for Svelte 5 (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama authored Jun 17, 2024
1 parent 8d75802 commit 437e463
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
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 },
/* ... */
},
},
{
"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;
}

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
}
}
}

0 comments on commit 437e463

Please sign in to comment.