{"record":{"id":"33d563b0ffedad5a","repo":"oxc-project/oxc","slug":"use-new-fn-name-instead-of-fn-name","errorCode":null,"errorMessage":"Use `new {fn_name}()` instead of `{fn_name}()`","messagePattern":"Use `new (.+?)\\(\\)` instead of `(.+?)\\(\\)`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs","lineNumber":13,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_syntax::operator::BinaryOperator;\n\nuse crate::{\n    AstNode, context::LintContext, globals::GLOBAL_OBJECT_NAMES, rule::Rule,\n    utils::call_uses_optional_chain,\n};\n\nfn enforce(span: Span, fn_name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Use `new {fn_name}()` instead of `{fn_name}()`\")).with_label(span)\n}\n\nfn disallow(span: Span, fn_name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Use `{fn_name}()` instead of `new {fn_name}()`\")).with_label(span)\n}\n\nfn error_date(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `String(new Date())` instead of `Date()`\").with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NewForBuiltins;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Enforces the use of `new` for the following builtins: `Object`, `Array`, `ArrayBuffer`, `BigInt64Array`,\n    /// `BigUint64Array`, `DataView`, `Date`, `Error`, `Float16Array`, `Float32Array`, `Float64Array`, `Function`, `Int8Array`,","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs#L1-L31","documentation":"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.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs:13 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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`"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}