{"record":{"id":"bceaec110d9abdcd","repo":"oxc-project/oxc","slug":"use-fn-name-instead-of-new-fn-name","errorCode":null,"errorMessage":"Use `{fn_name}()` instead of `new {fn_name}()`","messagePattern":"Use `(.+?)\\(\\)` instead of `new (.+?)\\(\\)`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs","lineNumber":17,"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`,\n    /// `Int16Array`, `Int32Array`, `Map`, `WeakMap`, `Set`, `WeakSet`, `Promise`, `RegExp`, `Uint8Array`,\n    /// `Uint16Array`, `Uint32Array`, `Uint8ClampedArray`, `SharedArrayBuffer`, `Proxy`, `WeakRef`, `FinalizationRegistry`.\n    ///\n    /// Disallows the use of `new` for the following builtins: `String`, `Number`, `Boolean`, `Symbol`, `BigInt`.","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs#L1-L35","documentation":"Raised by unicorn/new-for-builtins when configured to disallow `new`, for builtins (e.g. Object, Function, Array without args) where using the constructor form is discouraged. The faulting input is the `new FnName()` expression at the labeled span.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs:17 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Drop `new` and call the builtin directly, e.g. `Object(x)` instead of `new Object(x)`","Prefer literal forms like `{}`, `[]`, `() => {}` over the equivalent constructors"],"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"}