oxc-project/oxc · error · OxcDiagnostic

The function is equivalent to `{called_fn}`. Call `{called_f

Error message

The function is equivalent to `{called_fn}`. Call `{called_fn}` directly.

What it means

Diagnostic from the unicorn/prefer-native-coercion-functions lint rule. It fires when a function (declared or arrow) does nothing but coerce its first parameter and return it, e.g. `function toStr(v) { return String(v); }`; the wrapper is redundant and the native function named in the message (`String`, `Number`, `Boolean`) can be passed directly. The flagged input is the redundant function's span. It is a lint suggestion, not a runtime error.

Source

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

use oxc_ast::{
    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.
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace the wrapper with the native function itself, e.g. `arr.map(String)` instead of `arr.map(v => String(v))`
  2. Delete the now-unused wrapper declaration
  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:13 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/c9d8a9259fe96202. Report an issue: GitHub.