Skip to content

test(linter/plugins): tests use Oxc parser#16803

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-13-test_linter_plugins_tests_use_oxc_parser
Dec 13, 2025
Merged

test(linter/plugins): tests use Oxc parser#16803
graphite-app[bot] merged 1 commit intomainfrom
12-13-test_linter_plugins_tests_use_oxc_parser

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Dec 13, 2025

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).

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-linter-plugins Area - Linter JS plugins labels Dec 13, 2025
Copy link
Copy Markdown
Member Author

overlookmotel commented Dec 13, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-estree parser with Oxc's native parse function
  • Removed vi.mock() for source_code.ts and implemented a proper parse() 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.

Copy link
Copy Markdown

@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

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

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 .jsx path, but doesn’t pass options like jsx: true. If parseRaw() 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.ts to stop using @typescript-eslint/typescript-estree and instead parse snippets via the project’s Oxc parser (parseRaw).
  • Removed the vitest mock/override of source_code.ts’s sourceText and the associated mutable sourceText global.
  • Added a local parse(path, sourceText, options?) helper that:
    • calls setupFileContext(path)
    • invokes parseRaw(path, sourceText, options) and pulls the resulting buffer from buffers[0]
    • initializes and returns the global ast via initAst()
  • Updated tests to call parse("dummy.js", code) / parse("dummy.jsx", code) and to reset global state in beforeEach() via resetFileContext() + resetSourceAndAst().

@charliecreates charliecreates bot removed the request for review from CharlieHelps December 13, 2025 18:28
@overlookmotel overlookmotel self-assigned this Dec 13, 2025
@overlookmotel overlookmotel force-pushed the 12-13-test_linter_plugins_tests_use_oxc_parser branch from 8d2b90f to 005982b Compare December 13, 2025 18:42
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Dec 13, 2025
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Dec 13, 2025

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).
@graphite-app graphite-app bot force-pushed the 12-13-test_linter_plugins_tests_use_oxc_parser branch from 005982b to 5619f9e Compare December 13, 2025 18:51
@graphite-app graphite-app bot merged commit 5619f9e into main Dec 13, 2025
18 checks passed
@graphite-app graphite-app bot deleted the 12-13-test_linter_plugins_tests_use_oxc_parser branch December 13, 2025 18:57
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter A-linter-plugins Area - Linter JS plugins C-test Category - Testing. Code is missing test cases, or a PR is adding them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants