-
-
Notifications
You must be signed in to change notification settings - Fork 896
fix(linter/plugins): reset visitor compilation state if error during compilation #20166
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
graphite-app
merged 1 commit into
main
from
om/03-09-fix_linter_plugins_reset_visitor_compilation_state_if_error_during_compilation
Mar 10, 2026
Merged
Changes from all commits
Commits
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
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
7 changes: 7 additions & 0 deletions
7
apps/oxlint/test/fixtures/lint_invalid_visitor/.oxlintrc.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,7 @@ | ||
| { | ||
| "jsPlugins": ["./plugin.ts"], | ||
| "categories": { "correctness": "off" }, | ||
| "rules": { | ||
| "error-plugin/error": "error" | ||
| } | ||
| } |
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 @@ | ||
| let x; |
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 @@ | ||
| let y; |
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,3 @@ | ||
| { | ||
| "singleThread": true | ||
| } |
22 changes: 22 additions & 0 deletions
22
apps/oxlint/test/fixtures/lint_invalid_visitor/output.snap.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,22 @@ | ||
| # Exit code | ||
| 1 | ||
|
|
||
| # stdout | ||
| ``` | ||
| x Error running JS plugin. | ||
| | File path: <fixture>/files/1.js | ||
| | TypeError: 'Program' property of visitor object is not a function | ||
| x error-plugin(error): Identifier in 2nd file: y | ||
| ,-[files/2.js:1:5] | ||
| 1 | let y; | ||
| : ^ | ||
| `---- | ||
| Found 0 warnings and 2 errors. | ||
| Finished in Xms on 2 files with 1 rules using X threads. | ||
| ``` | ||
|
|
||
| # stderr | ||
| ``` | ||
| ``` |
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,64 @@ | ||
| import assert from "node:assert"; | ||
|
|
||
| import type { Plugin, Rule } from "#oxlint/plugins"; | ||
|
|
||
| // Aim of this test is: | ||
| // | ||
| // 1. Check that errors thrown during visitor compilation are handled correctly and shown to user as diagnostics. | ||
| // 2. Check that global state is reset after an error during visiting a file, so it's in correct initial state | ||
| // when Oxlint starts linting the next file. | ||
| // | ||
| // The 2nd is tricky to test because usually the order Oxlint lints files in is non-deterministic. | ||
| // To make this test deterministic, we run it with `oxlint --threads 1` | ||
| // (`options.json` file for this fixture contains `"singleThread": true`). | ||
| // This guarantees that `1.js` is linted before `2.js`. | ||
| // | ||
| // This rule throws an error during visitor compilation when linting 1st file. If global state is not reset properly | ||
| // before linting 2nd file, `Identifier` visitor for 1st file will not be cleaned up and will fire on 2nd file. | ||
|
|
||
| let fileIndex = 0; | ||
|
|
||
| const rule: Rule = { | ||
| create(context) { | ||
| const isFirstFileLinted = fileIndex === 0; | ||
| fileIndex++; | ||
|
|
||
| // Check the order files get linted in is what we expect | ||
| const isFirstFile = context.filename.endsWith("1.js"); | ||
| assert(isFirstFile === isFirstFileLinted); | ||
|
|
||
| if (isFirstFile) { | ||
| return { | ||
| Identifier(node) { | ||
| context.report({ | ||
| message: `Identifier in 1st file: ${node.name}`, | ||
| node, | ||
| }); | ||
| }, | ||
|
|
||
| // Illegal value, causes error during visitor compilation | ||
| Program: 123 as any, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| Identifier(node) { | ||
| context.report({ | ||
| message: `Identifier in 2nd file: ${node.name}`, | ||
| node, | ||
| }); | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
|
|
||
| const plugin: Plugin = { | ||
| meta: { | ||
| name: "error-plugin", | ||
| }, | ||
| rules: { | ||
| error: rule, | ||
| }, | ||
| }; | ||
|
|
||
| export default plugin; |
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.
Uh oh!
There was an error while loading. Please reload this page.