{"record":{"id":"d76497cb9b8963bd","repo":"oxc-project/oxc","slug":"use-string-new-date-instead-of-date","errorCode":null,"errorMessage":"Use `String(new Date())` instead of `Date()`","messagePattern":"Use `String\\(new Date\\(\\)\\)` instead of `Date\\(\\)`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs","lineNumber":21,"sourceCode":"use 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`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Using `new` inconsistently can cause confusion. Constructors like `Array` and `RegExp` should always use `new`","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs#L3-L39","documentation":"Lint diagnostic from unicorn/new-for-builtins (error_date): Date was called as a function. Unlike other builtins the rule enforces with new, Date() without new returns a string of the current time, which is almost never intended when a Date instance is required.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/new_for_builtins.rs:21 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use new Date() when a Date object is needed","Use String(new Date()) explicitly if a timestamp string is actually intended"],"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-14T05:17:10.506Z"}