Skip to content

fix(oxc_linter): allow string message in vitest valid-expect#18975

Open
cexbrayat wants to merge 2 commits intooxc-project:mainfrom
cexbrayat:fix/valid-expect-vitest
Open

fix(oxc_linter): allow string message in vitest valid-expect#18975
cexbrayat wants to merge 2 commits intooxc-project:mainfrom
cexbrayat:fix/valid-expect-vitest

Conversation

@cexbrayat
Copy link
Copy Markdown

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 in 2 commits:

  • the first one duplicates the jest rule int he vitest directory and registers it
  • the second one is the fix itself allowing the second parameter

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

@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
Duplicate valid-expect into vitest rules
and split snapshots/tests so vitest can diverge from jest

Refs oxc-project#18851
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