vitest/prefer-strict-boolean-matchers Style
What it does
This rule warns when toBeTruthy() or toBeFalsy() is used with expect or expectTypeOf. With --fix-suggestions, it will be replaced with toBe(true) or toBe(false).
Why is this bad?
Truthy/falsy matchers coerce values to boolean and can hide type mistakes. Strict boolean assertions make intent explicit and avoid accidental coercion. The replacement is a suggestion because it changes which values pass the assertion.
Examples
Examples of incorrect code for this rule:
javascript
expect(foo).toBeTruthy();
expectTypeOf(foo).toBeTruthy();
expect(foo).toBeFalsy();
expectTypeOf(foo).toBeFalsy();Examples of correct code for this rule:
javascript
expect(foo).toBe(true);
expectTypeOf(foo).toBe(true);
expect(foo).toBe(false);
expectTypeOf(foo).toBe(false);How to use
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vitest"],
"rules": {
"vitest/prefer-strict-boolean-matchers": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vitest"],
rules: {
"vitest/prefer-strict-boolean-matchers": "error",
},
});bash
oxlint --deny vitest/prefer-strict-boolean-matchers --vitest-pluginVersion
This rule was added in v1.57.0.
