Skip to content

linter: vitest/expect-expect – expectTypeOf not recognized as assertion when used as global (no explicit import from "vitest") #23547

Description

@antoinezanardi

What version of Oxlint are you using?

1.70.0

What command did you run?

oxlint -c oxlint.config.jsonc

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

{                                                                                                                                                                                  
       "plugins": ["vitest"],
       "globals": {
         "expect": "readonly",
         "expectTypeOf": "readonly"
       },                                                                                                                                       
       "overrides": [                                                                                                                          
         {                                                                                                                                                                              
           "files": ["**/*.spec.ts"],                                                                                                                                                   
           "plugins": ["vitest"],                                                                                                                                               
           "rules": {                                                                                                                                                                   
             "vitest/expect-expect": "error"                                                                                                                              
           }                                                                                                                                                                            
         }                                                                                                                                                                              
       ]                                                                                                                                                                                
     }      

What happened?

vitest/expect-expect reports a false positive when a test uses expectTypeOf as a global without an explicit import ... from "vitest".

Reproduction (repro.spec.ts):

it("should work", () => {
  expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>();
});

Actual output:

  x vitest(expect-expect): Test has no assertions

Expected: No diagnostic — expectTypeOf should be recognized as an assertion. The rule's documentation explicitly lists ["expect", "expectTypeOf", "assert", "assertType"] as the Vitest default.

Root cause: The shared implementation at crates/oxc_linter/src/rules/shared/jest_vitest/expect_expect.rs selects defaults based on ctx.frameworks().is_vitest():

let assert_function_names = if ctx.frameworks().is_vitest() {
    &rule.assert_function_names_vitest  // ["expect", "expectTypeOf", "assert", "assertType"]
} else {
    &rule.assert_function_names_jest     // ["expect"] only
};

Framework detection (has_vitest_imports in crates/oxc_linter/src/frameworks.rs) only checks for value imports from "vitest". When using Vitest with globals: true, there is no import, so is_vitest() returns false, and the rule falls back to the Jest defaults which only include ["expect"].

The vitest/expect-expect rule should unconditionally use the Vitest assertion function defaults regardless of import-based framework detection — the rule is already namespaced under vitest/.

Metadata

Metadata

Assignees

No one assigned

    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