oxc-project/oxc · error · OxcDiagnostic

Do not use ` ` as a constructor

Error message

Do not use `{builtin_name}` as a constructor

What it means

Lint diagnostic from eslint/no-new-wrappers: a primitive wrapper builtin (String, Number, Boolean) was used with new. Wrappers produce objects that behave subtly differently from primitives in comparisons and type checks; the rule wants literal/conversion forms instead.

Solutions

  1. Remove the new operator and use the conversion function form, e.g. String(x)
  2. Use literals (0, '', false) for primitive values
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/eslint/no_new_wrappers.rs:17 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/22c48e7d644c5c94. Report an issue: GitHub.

Appendix: source

Thrown at crates/oxc_linter/src/rules/eslint/no_new_wrappers.rs:17

use oxc_ast::{
    AstKind,
    ast::{Argument, Expression, NewExpression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

use crate::{
    AstNode,
    context::LintContext,
    fixer::{RuleFix, RuleFixer},
    rule::Rule,
};

fn no_new_wrappers_diagnostic(builtin_name: &str, new_span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Do not use `{builtin_name}` as a constructor"))
        .with_help("Remove the `new` operator.")
        .with_label(new_span)
}

fn not_a_constructor_diagnostic(builtin_name: &str, new_span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("`{builtin_name}` is not a constructor"))
        .with_help("Remove the `new` operator.")
        .with_label(new_span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow `new` operators with the `String`, `Number`, and `Boolean` objects.
    ///

View on GitHub (pinned to e1e7af627c)