Skip to content

linter: vitest/prefer-describe-function-title reports false positives on vi.spyOn prototype methods #18039

@antoinezanardi

Description

@antoinezanardi

What version of Oxlint are you using?

1.39.0

What command did you run?

oxlint --type-aware -c configs/oxlint/oxlint.config.jsonc

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

{
"vitest/prefer-describe-function-title": "error", 
}

What happened?

Hi 👋

I’m encountering what looks like a false positive with the rule
eslint-plugin-vitest(prefer-describe-function-title) when linting Vitest unit tests that use vi.spyOn on prototype methods.

The rule reports errors on method names passed to vi.spyOn, even though they are not describe titles and are unrelated to describe() blocks.


Minimal context

In a beforeEach, I create spies on a class prototype:

describe("Swagger Helper", () => {

beforeEach(() => {
    mocks = {
      DocumentBuilder: {
        setTitle: vi.spyOn(DocumentBuilder.prototype, "setTitle").mockReturnThis(),
        setDescription: vi.spyOn(DocumentBuilder.prototype, "setDescription").mockReturnThis(),
        setVersion: vi.spyOn(DocumentBuilder.prototype, "setVersion").mockReturnThis(),
        build: vi
          .spyOn(DocumentBuilder.prototype, "build")
          .mockReturnValue({} as Omit<OpenAPIObject, "paths">),
      },
    };
  });

// ...
});

Reported error

The linter reports the following error multiple times (once per spyOn call):

× eslint-plugin-vitest(prefer-describe-function-title):
Title description can not have the same content as a imported function name.

Error location points to the DocumentBuilder.prototype, used in vi.spyOn, for example:

vi.spyOn(DocumentBuilder.prototype, "build")

Why this seems incorrect

According to the rule documentation:
https://oxc.rs/docs/guide/usage/linter/rules/vitest/prefer-describe-function-title.html

This rule is meant to enforce better describe() titles, ensuring they are not identical to imported function names.

However, in this case:

  • The reported strings are method names, not describe titles
  • They are used as arguments to vi.spyOn
  • They are related to a describe, but not referring to a function name.

Reproduction

The full test file is available here:
https://github.com/antoinezanardi/goat-it-api/blob/main/src/infrastructure/api/server/swagger/helpers/swagger.helpers.spec.ts


Environment

  • Vitest
  • TypeScript
  • oxc linter
  • Rule: vitest/prefer-describe-function-title

Thanks a lot for your work on oxc 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions