fix(oxc_linter): allow string message in vitest valid-expect#18975
Open
cexbrayat wants to merge 2 commits intooxc-project:mainfrom
Open
fix(oxc_linter): allow string message in vitest valid-expect#18975cexbrayat wants to merge 2 commits intooxc-project:mainfrom
cexbrayat wants to merge 2 commits intooxc-project:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request adds support for Vitest's optional string message argument in the valid-expect rule, addressing issue #18851. Vitest allows expect(value, "custom message") where the second argument is a string or template literal for custom failure messages, which differs from Jest's strict one-argument requirement.
Changes:
- Created a new
vitest/valid_expectrule by duplicating the Jest rule - Modified the Vitest version to allow a second argument when it's a string literal or template literal
- Updated test suites to separate Jest and Vitest test cases
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_linter/src/rules/vitest/valid_expect.rs | New Vitest-specific valid-expect rule with logic to allow optional string message argument |
| crates/oxc_linter/src/rules/jest/valid_expect.rs | Cleaned up to remove Vitest-specific test cases |
| crates/oxc_linter/src/snapshots/vitest_valid_expect.snap | New snapshot file for Vitest rule tests |
| crates/oxc_linter/src/snapshots/jest_valid_expect.snap | Updated snapshot with Vitest tests removed |
| crates/oxc_linter/src/rules.rs | Added vitest/valid_expect module registration |
| crates/oxc_linter/src/generated/rules_enum.rs | Generated code for rule enum integration |
| crates/oxc_linter/src/generated/rule_runner_impls.rs | Generated code for rule runner implementation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5bd9250 to
2d87526
Compare
Duplicate valid-expect into vitest rules and split snapshots/tests so vitest can diverge from jest Refs oxc-project#18851
Allows a 2nd expect argument when it is a string or template literal, matching eslint-plugin-vitest behavior (https://github.com/vitest-dev/eslint-plugin-vitest/blob/472ba3d120e12eb7faa3d625c59679caa3ef2211/src/rules/valid-expect.ts#L315-L329). Fixes oxc-project#18851
2d87526 to
be3f609
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #18851
Allows a 2nd expect argument when it is a string or template literal,
matching eslint-plugin-vitest behavior (https://github.com/vitest-dev/eslint-plugin-vitest/blob/472ba3d120e12eb7faa3d625c59679caa3ef2211/src/rules/valid-expect.ts#L315-L329).
Now this won't throw an error:
As this diverges from the jest rule, the PR is in 2 commits: