fix(linter/valid-expect): allow string message in Vitest valid-expect#18975
fix(linter/valid-expect): allow string message in Vitest valid-expect#18975camc314 merged 1 commit intooxc-project:mainfrom
Conversation
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
2d87526 to
be3f609
Compare
be3f609 to
1ff43ac
Compare
2c59e4a to
51ec24d
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
1373a4a to
9895c94
Compare
9895c94 to
2d4174b
Compare
2d4174b to
616d034
Compare
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 on top #21430