-
Notifications
You must be signed in to change notification settings - Fork 234
fix(migration): add Svelte rune globals to Oxlint config #2192
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
Open
naokihaba
wants to merge
3
commits into
voidzero-dev:main
Choose a base branch
from
naokihaba:fix/svelte-rune-globals
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...li_snapshots/tests/cli_snapshots/fixtures/migration_eslint_svelte_runes/eslint.config.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| export default [ | ||
| { | ||
| rules: { | ||
| 'no-undef': 'error', | ||
| }, | ||
| }, | ||
| { | ||
| files: ['*.svelte', '**/*.svelte'], | ||
| rules: { | ||
| 'no-inner-declarations': 'off', | ||
| 'no-self-assign': 'off', | ||
| }, | ||
| }, | ||
| ]; |
10 changes: 10 additions & 0 deletions
10
...ite_cli_snapshots/tests/cli_snapshots/fixtures/migration_eslint_svelte_runes/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "migration-eslint-svelte-runes", | ||
| "scripts": { | ||
| "lint": "eslint ." | ||
| }, | ||
| "devDependencies": { | ||
| "eslint": "^9.0.0", | ||
| "vite": "^7.0.0" | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
...e_cli_snapshots/tests/cli_snapshots/fixtures/migration_eslint_svelte_runes/snapshots.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [[case]] | ||
| name = "migration_eslint_svelte_runes" | ||
| vp = "global" | ||
| steps = [ | ||
| { argv = ["vp", "migrate", "--no-interactive"], comment = "migration should add Svelte rune globals to the lint override", continue-on-failure = true }, | ||
| { argv = ["vpt", "print-file", "vite.config.ts"], comment = "Svelte override includes every built-in rune as a readonly global", continue-on-failure = true }, | ||
| { argv = ["vp", "lint", "src/App.svelte"], comment = "valid Svelte rune usage should pass no-undef", continue-on-failure = true }, | ||
| ] |
89 changes: 89 additions & 0 deletions
89
...xtures/migration_eslint_svelte_runes/snapshots/migration_eslint_svelte_runes.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # migration_eslint_svelte_runes | ||
|
|
||
| ## `vp migrate --no-interactive` | ||
|
|
||
| migration should add Svelte rune globals to the lint override | ||
|
|
||
| ``` | ||
| VITE+ - The Unified Toolchain for the Web | ||
|
|
||
| ◇ Migrated . to Vite+ <version> | ||
| • Node <version> pnpm <version> | ||
| • 4 config updates applied | ||
| • ESLint rules migrated to Oxlint | ||
| ``` | ||
|
|
||
| ## `vpt print-file vite.config.ts` | ||
|
|
||
| Svelte override includes every built-in rune as a readonly global | ||
|
|
||
| ``` | ||
| import { defineConfig } from 'vite-plus'; | ||
|
|
||
| export default defineConfig({ | ||
| staged: { | ||
| "*": "vp check --fix" | ||
| }, | ||
| fmt: {}, | ||
| lint: { | ||
| "plugins": [ | ||
| "oxc", | ||
| "typescript", | ||
| "unicorn", | ||
| "react" | ||
| ], | ||
| "categories": { | ||
| "correctness": "warn" | ||
| }, | ||
| "env": { | ||
| "builtin": true | ||
| }, | ||
| "rules": { | ||
| "no-undef": "error", | ||
| "vite-plus/prefer-vite-plus-imports": "error" | ||
| }, | ||
| "overrides": [ | ||
| { | ||
| "files": [ | ||
| "*.svelte", | ||
| "**/*.svelte" | ||
| ], | ||
| "rules": { | ||
| "no-inner-declarations": "off", | ||
| "no-self-assign": "off" | ||
| }, | ||
| "globals": { | ||
| "$state": "readonly", | ||
| "$derived": "readonly", | ||
| "$effect": "readonly", | ||
| "$props": "readonly", | ||
| "$bindable": "readonly", | ||
| "$inspect": "readonly", | ||
| "$host": "readonly" | ||
| } | ||
| } | ||
| ], | ||
| "options": { | ||
| "typeAware": true, | ||
| "typeCheck": true | ||
| }, | ||
| "jsPlugins": [ | ||
| { | ||
| "name": "vite-plus", | ||
| "specifier": "vite-plus/oxlint-plugin" | ||
| } | ||
| ] | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| ## `vp lint src/App.svelte` | ||
|
|
||
| valid Svelte rune usage should pass no-undef | ||
|
|
||
| ``` | ||
| VITE+ - The Unified Toolchain for the Web | ||
|
|
||
| Found 0 warnings and 0 errors. | ||
| Finished in <duration> on 1 file with <n> rules using <n> threads. | ||
| ``` |
5 changes: 5 additions & 0 deletions
5
...e_cli_snapshots/tests/cli_snapshots/fixtures/migration_eslint_svelte_runes/src/App.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <script> | ||
| let { name = 'world' } = $props(); | ||
| </script> | ||
|
|
||
| <h1>Hello {name}</h1> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Svelte components that use valid store auto-subscriptions such as
$count(wherecountis a Svelte store), enumerating only the built-in rune names still leaves the migrated top-levelno-undefrule active and Oxlint will continue reporting those$...references as undefined. This means migrated/generated Svelte projects with stores can still failvp check; the Svelte override needs to turn offno-undef(or otherwise account for dynamic store subscriptions) rather than only adding a fixed globals list.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disabling no-undef weakens our checks for undefined variables, so I think the best quick fix is to register Runes as globals.
I wanted to avoid turning off no-undef for all .svelte files, so I chose to register each Rune individually. Disabling it globally runs the risk of missing real errors. We already agreed on this approach in #1967.
So, this PR focuses on properly supporting Runes like $props(). Supporting custom user store variables is out of scope for now.