Skip to content

linter: false positive on eslint-plugin-jest(expect-expect) #12869

@yunarch

Description

@yunarch

What version of Oxlint are you using?

1.10.0

What command did you run?

oxlint

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

A minimum reproducible config to see the false positive:

// .oxlintrc.json
{
  "$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
  "plugins": ["vitest"],
  "overrides": [
    {
      "files": [
        "**/__tests__/**/*.{js,jsx,cjs,cjsx,mjs,mjsx,ts,tsx,cts,ctsx,mts,mtjsx}",
        "**/*.spec.{js,jsx,cjs,cjsx,mjs,mjsx,ts,tsx,cts,ctsx,mts,mtjsx}",
        "**/*.test.{js,jsx,cjs,cjsx,mjs,mjsx,ts,tsx,cts,ctsx,mts,mtjsx}",
        "**/*.bench.{js,jsx,cjs,cjsx,mjs,mjsx,ts,tsx,cts,ctsx,mts,mtjsx}",
        "**/*.benchmark.{js,jsx,cjs,cjsx,mjs,mjsx,ts,tsx,cts,ctsx,mts,mtjsx}"
      ],
      "rules": {
        "vitest/expect-expect": "error"
      }
    }
  ]
}

What happened?

After updating to 1.10.0, the following test triggers the expect-expect rule, reporting that the test has no assertions:

it('example test', async () => {
    await Promise.all([
      expect(
        new Promise((resolve) => {
          resolve(1);
        })
      ).resolves.toBe(1),
      expect(
        new Promise((_, reject) => {
          reject(new Error('Failed'));
        })
      ).rejects.toThrowError('Failed'),
    ]);
  });

However, the test clearly contains two assertions. In previous version 1.9.0 this code did not produce any errors. So it seems like this could be a regression or a change in how the rule interprets assertions.

For comparison, this version has no issue:

  it('example test', async () => {
    await expect(
      new Promise((resolve) => {
        resolve(1);
      })
    ).resolves.toBe(1);
    await expect(
      new Promise((_, reject) => {
        reject(new Error('Failed'));
      })
    ).rejects.toThrowError('Failed');
  });

I think both versions are valid tests, at least they pass without problems and behave identically in terms of assertions. I understand the first version may be more difficult to analyze statically, but since it worked previously, I'm wondering if this is an unintentional regression in 1.10.0

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions