Skip to content

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

@cexbrayat

Description

@cexbrayat

What version of Oxlint are you using?

1.42.0

What command did you run?

oxlint ./tests

What does your .oxlintrc.json config file look like?

{
  "plugins": ["vitest"],
}

What happened?

The valid-expect rule currently enforces a strict 1-argument limit for expect(). This is correct for Jest, but Vitest supports an optional second argument for a custom failure message (e.g., expect(value, 'message').toBe(value)).

See the Vitest documentation for details on the message argument.

Currently, valid Vitest code like this triggers a false positive:

import { expect, test } from 'vitest'

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

gives:

> valid-exprect-repro@1.0.0 lint 
> oxlint ./tests


  ⚠ eslint-plugin-jest(valid-expect): Expect takes at most 1 argument 
   ╭─[tests/sum.test.js:4:3]
 3 │ test('adds 1 + 2 to equal 3', () => {
 4 │   expect(1 + 2, "sum is incorrect").toBe(4)
   ·   ─────────────────────────────────
 5 │ })
   ╰────
  help: Remove the extra arguments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions