oxc-project/oxc · error · OxcDiagnostic
Use `{to_be_literal}` instead of `{matcher_name}`.
Error message
Use `{to_be_literal}` instead of `{matcher_name}`. What it means
Emitted by the vitest/prefer-strict-boolean-matchers rule at an expectation using the loose boolean matchers `toBeTruthy()`/`toBeFalsy()`. It fires because these matchers accept any truthy/falsy value; strict `toBe(true)`/`toBe(false)` assertions catch accidental non-boolean values.
Source
Thrown at crates/oxc_linter/src/rules/vitest/prefer_strict_boolean_matchers.rs:16
use oxc_ast::{AstKind, ast::Expression};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{
context::LintContext,
rule::Rule,
utils::{PossibleJestNode, parse_expect_and_typeof_vitest_fn_call},
};
fn prefer_strict_boolean_matchers_diagnostic(span: Span, value: bool) -> OxcDiagnostic {
let (matcher_name, to_be_literal) =
if value { ("toBeTruthy", "toBe(true)") } else { ("toBeFalsy", "toBe(false)") };
OxcDiagnostic::warn(format!("Use `{to_be_literal}` instead of `{matcher_name}`."))
.with_help("Use strict boolean comparison instead of truthy/falsy coercion.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct PreferStrictBooleanMatchers;
declare_oxc_lint!(
/// ### What it does
///
/// Enforce using `toBe(true)` and `toBe(false)` over matchers that coerce types to boolean.
///
/// ### 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.
///
/// ### ExamplesView on GitHub (pinned to e1e7af627c)
Solutions
- Replace `toBeTruthy()` with `toBe(true)` and `toBeFalsy()` with `toBe(false)`
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/vitest/prefer_strict_boolean_matchers.rs:16 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/fdc8b44e08e9f1bf.
Report an issue: GitHub.