Vitest test.for S2187 false positive

  • Operating system: Linux Mint 22.1
  • SonarQube for IntelliJ plugin version: 10.27.1.81796
  • IntelliJ version: WebStorm 2025.1.2, WS-251.26094.131
  • Programming language you’re coding in: TypeScript
  • Is connected mode used: No

When a Vitest test.ts file exists with only test.for tests, the SonarQube for IDE Plugin raises S2187.

image

test.for is functionally similar to test.each, providing additional enhancements, and works as a test so S2187 should not be raised.

See https://vitest.dev/api/#test-for as a reference.

example.test.ts

import { test } from "vitest";

// Below are both detected by SonarQube and do not raise S2187
// test("", () => {});
// test.each([{ foo: "bar" }])("test name", ({ foo }) => {});

// This is not detected by SonarQube and raises S2187
test.for([{ foo: "bar" }])("test name", ({ foo }) => {});

Thank you for reporting. We just pushed a fix (JS-804 Add a few more test fqns by zglicz · Pull Request #5542 · SonarSource/SonarJS · GitHub) and the improvement will be available in the next release of SonarJS.

Cheers,
Michal

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.