Skip to content

Comments

refactor(linter): check valid Vitest calls with pattern matching#16924

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-15-refactor_linter_ucheck_valid_vitest_calls_with_pattern_matching
Dec 16, 2025
Merged

refactor(linter): check valid Vitest calls with pattern matching#16924
graphite-app[bot] merged 1 commit intomainfrom
12-15-refactor_linter_ucheck_valid_vitest_calls_with_pattern_matching

Conversation

@camchenry
Copy link
Member

@camchenry camchenry commented Dec 16, 2025

This trades compile time + binary size for maybe slightly less performance when checking Vitest function calls. We currently have to manually maintain this list which is a bit difficult to do as aliases make this list grow quickly. This is not sustainable long-term if more functions and aliases get added, so I'm proposing we make the switch now.

As part of this I also removed support for fdescribe, fit, xdescribe, xit, etc. as these don't actually seem to be supported in Vitest? At least I didn't find any references to them in the docs or in the source code, so I think this might have been a mistake when copying from the Jest version.

@github-actions github-actions bot added A-linter Area - Linter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Dec 16, 2025
Copy link
Member Author

camchenry commented Dec 16, 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.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 16, 2025

CodSpeed Performance Report

Merging #16924 will not alter performance

Comparing 12-15-refactor_linter_ucheck_valid_vitest_calls_with_pattern_matching (2c7ba8c) with main (c897794)1

Summary

✅ 4 untouched
⏩ 41 skipped2

Footnotes

  1. No successful run was found on main (ce943c6) during the generation of this report, so c897794 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 41 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@camchenry camchenry changed the title refactor(linter): ucheck valid Vitest calls with pattern matching refactor(linter): check valid Vitest calls with pattern matching Dec 16, 2025
@camchenry camchenry marked this pull request as ready for review December 16, 2025 02:58
@camchenry camchenry requested a review from camc314 as a code owner December 16, 2025 02:58
Copilot AI review requested due to automatic review settings December 16, 2025 02:58
Copy link
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 Vitest function call validation from a compile-time PHF (Perfect Hash Function) set containing 1,305 hardcoded entries to a runtime pattern-matching approach. The new implementation validates function chains by checking the base function name and then applying modifier-specific validation rules (e.g., "each" must be last, "extend" must be first for it/test, no duplicates allowed). This significantly reduces compile time and binary size while making the codebase more maintainable, though it may have a slight runtime performance cost.

Key Changes

  • Replaced 1,305-line PHF set with ~80 lines of rule-based validation logic
  • Changed API signature from is_valid_vitest_call(&[Cow<str>]) to generic is_valid_vitest_call<T: AsRef<str>>(&[T])
  • Added explicit validation rules for modifiers per function type (bench, describe/suite, it/test)
  • Removed support for Jest-style prefix functions (fdescribe, fit, xdescribe, xit, xtest) which were deprecated aliases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/oxc_linter/src/utils/vitest/valid_vitest_fn.rs Complete rewrite of validation logic from PHF set lookup to pattern matching with modifier-specific rules and comprehensive test coverage
crates/oxc_linter/src/rules/jest/require_hook.rs Updated function call to remove Cow::Borrowed wrapper, leveraging the new generic API

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@camchenry camchenry force-pushed the 12-15-refactor_linter_ucheck_valid_vitest_calls_with_pattern_matching branch from 0b002f9 to 2c7ba8c Compare December 16, 2025 04:17
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Dec 16, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Dec 16, 2025

Merge activity

)

This trades compile time + binary size for maybe slightly less performance when checking Vitest function calls. We currently have to manually maintain this list which is a bit difficult to do as aliases make this list grow quickly. This is not sustainable long-term if more functions and aliases get added, so I'm proposing we make the switch now.

As part of this I also removed support for `fdescribe`, `fit`, `xdescribe`, `xit`, etc. as these don't actually seem to be supported in Vitest? At least I didn't find any references to them in the docs or in the source code, so I think this might have been a mistake when copying from the Jest version.
@graphite-app graphite-app bot force-pushed the 12-15-refactor_linter_ucheck_valid_vitest_calls_with_pattern_matching branch from 2c7ba8c to 561abd0 Compare December 16, 2025 09:10
@graphite-app graphite-app bot merged commit 561abd0 into main Dec 16, 2025
20 checks passed
@graphite-app graphite-app bot deleted the 12-15-refactor_linter_ucheck_valid_vitest_calls_with_pattern_matching branch December 16, 2025 09:15
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 16, 2025
qinyuhang pushed a commit to qinyuhang/oxc that referenced this pull request Jan 22, 2026
…-project#16924)

This trades compile time + binary size for maybe slightly less performance when checking Vitest function calls. We currently have to manually maintain this list which is a bit difficult to do as aliases make this list grow quickly. This is not sustainable long-term if more functions and aliases get added, so I'm proposing we make the switch now.

As part of this I also removed support for `fdescribe`, `fit`, `xdescribe`, `xit`, etc. as these don't actually seem to be supported in Vitest? At least I didn't find any references to them in the docs or in the source code, so I think this might have been a mistake when copying from the Jest version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant