vitest/prefer-to-be-falsy Style
What it does
This rule warns when toBe(false) is used with expect or expectTypeOf. With --fix-suggestions, it will be replaced with toBeFalsy().
Why is this bad?
When testing for falsiness, toBeFalsy() expresses that intent directly. Unlike toBe(false), it also accepts non-boolean falsy values such as 0, null, and undefined. The replacement is a suggestion because it changes which values pass the assertion.
Examples
Examples of incorrect code for this rule:
javascript
expect(foo).toBe(false);
expectTypeOf(foo).toBe(false);Examples of correct code for this rule:
javascript
expect(foo).toBeFalsy();
expectTypeOf(foo).toBeFalsy();How to use
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vitest"],
"rules": {
"vitest/prefer-to-be-falsy": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vitest"],
rules: {
"vitest/prefer-to-be-falsy": "error",
},
});bash
oxlint --deny vitest/prefer-to-be-falsy --vitest-pluginVersion
This rule was added in v0.7.1.
