Skip to content

fix(linter/valid-expect): allow string message in Vitest valid-expect#18975

Merged
camc314 merged 1 commit intooxc-project:mainfrom
cexbrayat:fix/valid-expect-vitest
Apr 27, 2026
Merged

fix(linter/valid-expect): allow string message in Vitest valid-expect#18975
camc314 merged 1 commit intooxc-project:mainfrom
cexbrayat:fix/valid-expect-vitest

Conversation

@cexbrayat
Copy link
Copy Markdown
Contributor

@cexbrayat cexbrayat commented Feb 5, 2026

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:

import { expect, test } from 'vitest'

test('adds 1 + 2 to equal 3', () => {
  expect(1 + 2, "sum is incorrect").toBe(4)
})

As this diverges from the jest rule, the PR is on top #21430

@cexbrayat cexbrayat requested a review from camc314 as a code owner February 5, 2026 08:28
Copilot AI review requested due to automatic review settings February 5, 2026 08:28
@github-actions github-actions Bot added A-linter Area - Linter C-bug Category - Bug labels Feb 5, 2026
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 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_expect rule 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.

Comment thread crates/oxc_linter/src/rules/vitest/valid_expect.rs Outdated
Comment thread crates/oxc_linter/src/rules/vitest/valid_expect.rs Outdated
@cexbrayat cexbrayat force-pushed the fix/valid-expect-vitest branch 2 times, most recently from 5bd9250 to 2d87526 Compare February 5, 2026 09:07
@camc314 camc314 self-assigned this Feb 10, 2026
@cexbrayat cexbrayat force-pushed the fix/valid-expect-vitest branch from 2d87526 to be3f609 Compare March 10, 2026 14:59
@cexbrayat cexbrayat force-pushed the fix/valid-expect-vitest branch from be3f609 to 1ff43ac Compare April 14, 2026 13:23
@cexbrayat cexbrayat changed the title fix(oxc_linter): allow string message in vitest valid-expect fix(linter/valid-expect): allow string message in Vitest valid-expect Apr 14, 2026
@cexbrayat cexbrayat force-pushed the fix/valid-expect-vitest branch 2 times, most recently from 2c59e4a to 51ec24d Compare April 14, 2026 13:29
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 14, 2026

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing cexbrayat:fix/valid-expect-vitest (616d034) with main (0c0e741)

Open in CodSpeed

Footnotes

  1. 47 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.

@cexbrayat cexbrayat force-pushed the fix/valid-expect-vitest branch 3 times, most recently from 1373a4a to 9895c94 Compare April 14, 2026 14:58
@cexbrayat cexbrayat force-pushed the fix/valid-expect-vitest branch from 9895c94 to 2d4174b Compare April 27, 2026 10:36
@cexbrayat cexbrayat force-pushed the fix/valid-expect-vitest branch from 2d4174b to 616d034 Compare April 27, 2026 10:41
Copy link
Copy Markdown
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

Thank you!

@camc314 camc314 merged commit b6dcc22 into oxc-project:main Apr 27, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: Support optional message argument in Vitest valid-expect rule

3 participants