oxc-project/oxc · error · OxcDiagnostic
Do not use 'new' for side effects.
Error message
Do not use 'new' for side effects.
What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_new.rs:10
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::AstNode;
use oxc_span::{GetSpan, Span};
use crate::{ast_util::outermost_paren_parent, context::LintContext, rule::Rule};
fn no_new_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Do not use 'new' for side effects.")
.with_help("Assign the result of 'new' to a variable or compare it to a reference.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoNew;
declare_oxc_lint!(
/// ### What it does
///
/// Disallow new operators outside of assignments or comparisons.
///
/// ### Why is this bad?
///
/// Calling new without assigning or comparing it the reference is thrown away and in many
/// cases the constructor can be replaced with a function.
///
/// ### ExamplesView on GitHub (pinned to e1e7af627c)
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
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/eslint/no_new.rs:10 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/452cb51677be5902.
Report an issue: GitHub.