{"record":{"id":"452cb51677be5902","repo":"oxc-project/oxc","slug":"do-not-use-new-for-side-effects","errorCode":null,"errorMessage":"Do not use 'new' for side effects.","messagePattern":"Do not use 'new' for side effects\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/eslint/no_new.rs","lineNumber":10,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::AstNode;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{ast_util::outermost_paren_parent, context::LintContext, rule::Rule};\n\nfn no_new_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not use 'new' for side effects.\")\n        .with_help(\"Assign the result of 'new' to a variable or compare it to a reference.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoNew;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow new operators outside of assignments or comparisons.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Calling new without assigning or comparing it the reference is thrown away and in many\n    /// cases the constructor can be replaced with a function.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_new.rs#L1-L28","documentation":"Lint diagnostic from eslint/no-new: a NewExpression statement's result is discarded (not assigned or compared). Constructing for side effects suggests the type is being abused; the allocation is wasted and the convention is considered an error-prone pattern.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/eslint/no_new.rs:10 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Assign the constructed instance to a variable","Compare the result to a reference if existence is what matters","Move the side effect into an explicit method call on an existing object"],"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"}