test(linter/plugins): tests use Oxc parser#16803
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR refactors the isSpaceBetween.test.ts test file to use the Oxc parser instead of @typescript-eslint/typescript-estree, and removes the mocking of source_code.ts. The tests now set up global state the same way as when files are being linted, bringing them closer to real usage and preparing for changes to token parsing in a follow-up PR.
Key changes:
- Replaced
@typescript-eslint/typescript-estreeparser with Oxc's nativeparsefunction - Removed
vi.mock()forsource_code.tsand implemented a properparse()helper function that sets up global state - Simplified test code by removing manual parser options and relying on file extension-based type detection
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
The main risk is test flakiness/order dependence: the new parse() helper reads from buffers[0] without clearing or validating buffers, so a previous test run could influence later ones. There’s also a small comment typo, and the hard-coded hasBOM: false / empty parserServices may diverge from the stated goal of mirroring real linting behavior. Addressing buffer determinism is important before relying on these tests as a foundation for subsequent token-parsing changes.
Additional notes (1)
- Maintainability |
apps/oxlint/test/isSpaceBetween.test.ts:98-98
The helper parses JSX test cases using only a.jsxpath, but doesn’t pass options likejsx: true. IfparseRaw()infers syntax purely from file extension today, this is fine; but the tests are now implicitly dependent on that inference behavior.
Given the PR’s stated goal (closer to real usage and preparing for token parsing changes), it’s better for the tests to be explicit about the syntax features they require so they don’t start failing when inference rules change.
Summary of changes
What changed
- Reworked
apps/oxlint/test/isSpaceBetween.test.tsto stop using@typescript-eslint/typescript-estreeand instead parse snippets via the project’s Oxc parser (parseRaw). - Removed the
vitestmock/override ofsource_code.ts’ssourceTextand the associated mutablesourceTextglobal. - Added a local
parse(path, sourceText, options?)helper that:- calls
setupFileContext(path) - invokes
parseRaw(path, sourceText, options)and pulls the resulting buffer frombuffers[0] - initializes and returns the global
astviainitAst()
- calls
- Updated tests to call
parse("dummy.js", code)/parse("dummy.jsx", code)and to reset global state inbeforeEach()viaresetFileContext()+resetSourceAndAst().
8d2b90f to
005982b
Compare
Merge activity
|
Pure refactor of tests. Unit tests for `isSpaceBetween` were using `@typescript-eslint/typescript-estree` to parse code snippets. Instead use Oxc parser, and set up global state the same way as if the file was being linted, instead of mocking `source_code.ts` to get the source text into the linter's internals. This brings the tests closer to real usage. It also prepares the way for changing how tokens are parsed in a following PR (#16805).
005982b to
5619f9e
Compare

Pure refactor of tests.
Unit tests for
isSpaceBetweenwere using@typescript-eslint/typescript-estreeto parse code snippets.Instead use Oxc parser, and set up global state the same way as if the file was being linted, instead of mocking
source_code.tsto get the source text into the linter's internals.This brings the tests closer to real usage. It also prepares the way for changing how tokens are parsed in a following PR (#16805).