Skip to content

fix(linter): skip test.extend() in expect-expect and no-disabled-tests#21201

Closed
masseater wants to merge 3 commits intooxc-project:mainfrom
masseater:fix/vitest-extend-false-positive
Closed

fix(linter): skip test.extend() in expect-expect and no-disabled-tests#21201
masseater wants to merge 3 commits intooxc-project:mainfrom
masseater:fix/vitest-extend-false-positive

Conversation

@masseater
Copy link
Copy Markdown

@masseater masseater commented Apr 9, 2026

Currently being reviewed by a human.

Summary

  • Fix false positives for vitest/expect-expect and vitest/no-disabled-tests when using test.extend() to create fixture-based test contexts
  • test.extend() is a test factory (creates new test functions with fixtures), not a test call itself, so it should not trigger these lint rules
  • Follows the same pattern already used in valid-title rule and aligns with the upstream fix in eslint-plugin-vitest#584

Reproduction

import { describe, expect, test } from 'vitest';

describe('example', () => {
  const it = test.extend<{ result: number }>({
    result: async ({}, use) => {
      await use(42);
    },
  });

  it('works', ({ result }) => {
    expect(result).toBe(42);
  });
});

Before this fix, test.extend() was incorrectly flagged as:

  • expect-expect: "Test has no assertions"
  • no-disabled-tests: "Test is missing function argument"

Changes

expect_expect.rs

Added extend to the early-return check alongside todo and skip:

if property_name == "extend" {
    return;
}

no_disabled_tests.rs

Added an early-return when the first member is extend (same pattern as valid_title.rs):

if let Some(member) = members.first()
    && member.is_name_equal("extend")
{
    return;
}

Test plan

  • Added pass test cases for test.extend() in both Jest and Vitest contexts for expect-expect
  • Added pass test cases for test.extend() in both Jest and Vitest contexts for no-disabled-tests
  • cargo test -p oxc_linter -- expect_expect passes
  • cargo test -p oxc_linter -- no_disabled_tests passes
  • cargo clippy -p oxc_linter passes without new warnings

AI Disclosure

This PR was authored with the assistance of Claude Code (AI).
The contributor has reviewed, tested, and validated all changes.

…-tests`

`test.extend()` is a Vitest test factory for creating fixture-based test
contexts, not a test call itself. Both `expect-expect` and `no-disabled-tests`
were incorrectly treating it as a test call, causing false positives.

This aligns with the fix in eslint-plugin-vitest (vitest-dev/eslint-plugin-vitest#584)
and follows the same pattern already used in `valid-title`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@masseater masseater requested a review from camc314 as a code owner April 9, 2026 03:36
@github-actions github-actions Bot added A-linter Area - Linter C-bug Category - Bug labels Apr 9, 2026
@Afsoon
Copy link
Copy Markdown
Contributor

Afsoon commented Apr 9, 2026

I think the correct approach is adding a ParsedJestFnCall::TestFixture to filter correctly during the parse phase, but it requires more work.

JustFly1984 added a commit to JustFly1984/oxc that referenced this pull request Apr 10, 2026
…-tests`

Cherry-picked from oxc-project#21201 (commit f71099d)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@camc314 camc314 self-assigned this Apr 15, 2026
camc314 added a commit that referenced this pull request Apr 23, 2026
…functions (#21668)

# AI Disclosure
The code has been done without AI help.

# Summary

A [previous PR](#21201) fixed
this false positive directly in the rule. This PR take another approach,
add a new Fixture Kind. This PR solely solve the false positive, a
follow PR, or PRs, need to addres the identifier tracking.


closes #21201

Co-authored-by: Cameron <cameron.clark@hey.com>
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.

3 participants