Skip to content

linter: behavior of no-standalone-expect rule differs between eslint and oxlint #17426

Description

@lld4n

What version of Oxlint are you using?

1.35.0

What command did you run?

oxlint

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

{
  "plugins": ["jest", "vitest"],
  "rules": {
    "vitest/no-standalone-expect": "error"
  }
}

What happened?

A similar situation occurs in vitest/no-standalone-expect and jest/no-standalone-expect

I use the no-standalone-expect rule for tests inside Angular projects. The key feature of these tests is that they allow the use of built-in Angular testing capabilities. For example, the fakeAsync function from the @angular/core/testing library. It allows you to stabilize asynchronous tests.

But I ran into a problem that the default behavior of the no-standalone-expect rule in Eslint and Oxlint is different.

Eslint config:

import {defineConfig} from 'eslint/config'
import vitest from '@vitest/eslint-plugin'

export default defineConfig({
  plugins: {
    vitest,
  },
  rules: {
    'vitest/no-standalone-expect': 'error'
  },
})
@vitest/eslint-plugin: 1.6.4
eslint: 9.39.2

I have a test written in my code like this:

import {fakeAsync} from '@angular/core/testing';

describe('App', () => {
  it('should create the app', fakeAsync(() => {
    expect(true).toBeTruthy();
  }));
});

I'm getting an error in oxlint:

  × eslint-plugin-jest(no-standalone-expect): `expect` must be inside of a test block.
   ╭─[file:///~/oxlint-jest-issue/src/app/app.spec.ts:5:5]
 4 │   it('should create the app', fakeAsync(() => {
 5 │     expect(true).toBeTruthy();
   ·     ──────
 6 │   }));
   ╰────
  help: Did you forget to wrap `expect` in a `test` or `it` block?

This is correct from the logic point of view of the rule, but the main problem is that the original eslint rule does not throw an error for this case. I know about additionalTestBlockFunctions, but I assume (I could be wrong) that oxlint rules should perfectly match eslint rules in behavior. Or at least have some documentation indicating that the behavior in this rule may differ.

You can visually check the behavior in this repository - https://github.com/lld4n/oxlint-vitest-issue

Metadata

Metadata

Labels

Type

Fields

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions