oxc-project/oxc · error · OxcDiagnostic

The arrow function in the callback of the array is equivalen

Error message

The arrow function in the callback of the array is equivalent to `Boolean`. Replace the callback with `Boolean`.

What it means

Diagnostic from the unicorn/prefer-native-coercion-functions lint rule. It fires when an array method's callback is an arrow function that merely coerces its argument to a boolean, e.g. `arr.filter(x => Boolean(x))`; the native `Boolean` function is behaviorally identical and can replace the callback directly. The flagged input is the callback arrow function. It is a lint suggestion, not a runtime error.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs:20

    AstKind,
    ast::{Argument, Expression, FormalParameters, FunctionBody, Statement, TSType},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::NodeId;
use oxc_span::{GetSpan, Span};

use crate::{AstNode, context::LintContext, rule::Rule, utils::get_first_parameter_name};

fn function(span: Span, called_fn: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "The function is equivalent to `{called_fn}`. Call `{called_fn}` directly."
    ))
    .with_label(span)
}

fn array_callback(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("The arrow function in the callback of the array is equivalent to `Boolean`. Replace the callback with `Boolean`.")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct PreferNativeCoercionFunctions;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Prefers built-in functions over custom ones with the same functionality.
    ///
    /// ### Why is this bad?
    ///
    /// If a function is equivalent to [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt), [`Boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean), or [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), you should use the built-in one directly.
    /// Wrapping the built-in in a function is moot.
    ///
    /// ### Examples
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace the callback with `Boolean`, e.g. `arr.filter(Boolean)`
  2. Consider `arr.filter(x => !!x)` alternatives only if the rule allows; `Boolean` is the canonical fix
  3. Apply the rule's auto-fix
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/prefer_native_coercion_functions.rs:20 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/4b036724dc7941e5. Report an issue: GitHub.