oxc-project/oxc · error · OxcDiagnostic
Use `new {fn_name}()` instead of `{fn_name}()`
Error message
Use `new {fn_name}()` instead of `{fn_name}()` What it means
Raised by unicorn/new-for-builtins in its default mode when a builtin constructor (e.g. Object, Array, Map, Error) that requires `new` is called as a plain function. The rule detects calls to known builtin globals during run(); the faulting input is the constructor call at the labeled span.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs:13
use oxc_ast::{AstKind, ast::Expression};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use oxc_syntax::operator::BinaryOperator;
use crate::{
AstNode, context::LintContext, globals::GLOBAL_OBJECT_NAMES, rule::Rule,
utils::call_uses_optional_chain,
};
fn enforce(span: Span, fn_name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Use `new {fn_name}()` instead of `{fn_name}()`")).with_label(span)
}
fn disallow(span: Span, fn_name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Use `{fn_name}()` instead of `new {fn_name}()`")).with_label(span)
}
fn error_date(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Use `String(new Date())` instead of `Date()`").with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NewForBuiltins;
declare_oxc_lint!(
/// ### What it does
///
/// Enforces the use of `new` for the following builtins: `Object`, `Array`, `ArrayBuffer`, `BigInt64Array`,
/// `BigUint64Array`, `DataView`, `Date`, `Error`, `Float16Array`, `Float32Array`, `Float64Array`, `Function`, `Int8Array`,View on GitHub (pinned to e1e7af627c)
Solutions
- Change `FnName()` to `new FnName()` for builtins that must be constructed
- Enable the rule's `allow`/invert mode if you intentionally construct a value-less builtin without `new`
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/new_for_builtins.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/33d563b0ffedad5a.
Report an issue: GitHub.