{"record":{"id":"6d3f9089fcbbb704","repo":"oxc-project/oxc","slug":"this-assigned-value-is-not-used-in-subsequent-stat","errorCode":null,"errorMessage":"This assigned value is not used in subsequent statements.","messagePattern":"This assigned value is not used in subsequent statements\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_useless_assignment.rs","lineNumber":26,"sourceCode":"        AssignmentTarget as AstAssignmentTarget, BindingPattern, Expression,\n        VariableDeclarationKind,\n    },\n};\nuse oxc_cfg::{\n    BasicBlockId, BlockNodeId, ControlFlowGraph, EdgeType, ErrorEdgeKind, Graph,\n    graph::{\n        Direction,\n        visit::{Control, DfsEvent, EdgeRef, depth_first_search},\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_index::IndexVec;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::{NodeId, Reference, ScopeId, SymbolId};\nuse oxc_span::GetSpan;\nuse oxc_span::Span;\n\nuse crate::{context::LintContext, rule::Rule};\n\nfn no_useless_assignment_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"This assigned value is not used in subsequent statements.\")\n        .with_help(\"Consider removing or reusing the assigned value.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoUselessAssignment;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Flags assignments where the newly assigned value is never read afterward (a \"dead store\"). This helps catch wasted work or accidental mistakes.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Dead stores add noise and can hide real bugs (e.g., you meant to use that value or wrote to the wrong variable). Removing them improves clarity and performance.","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/oxc-project/oxc/blob/1f902a69625cd14e6d8dc58feca94da099d2d251/crates/oxc_linter/src/rules/eslint/no_useless_assignment.rs#L8-L44","documentation":"Diagnostic from oxlint's no-useless-assignment rule. It flags a dead store: the value assigned at this span is never read on any subsequent path (overwritten first, or the scope/function exits), built from oxc_semantic reference and scope data (SymbolId/Reference/ScopeId).","triggerScenarios":"let x = compute(); throw new Error(); where x is never read; x = 1; x = 2; use(x); where the first write is dead; an assignment after the last read inside a branch that then returns.","commonSituations":"Accumulator variables replaced wholesale; state resets at the end of loop iterations nobody reads; assignments stranded above an early-return guard added later; debug assignments left after final use.","solutions":["Remove the never-read assignment.","Reorder so the assignment sits after any exit point and immediately before the first read.","Hoist to const at the point of single use.","If the RHS has side effects, keep the call but make discarding its result explicit."],"exampleFix":"// before\nfunction f(xs) {\n  let last;\n  for (const x of xs) { last = x; }\n  last = xs[0];\n  return last;\n}\n// after\nfunction f(xs) {\n  let last;\n  for (const x of xs) { last = x; }\n  return last;\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Initialize at declaration with const instead of declaring then assigning later.","When inserting early returns or throws, verify every assignment above them is still consumed.","Watch for state resets at iteration end; if nothing reads them next iteration, delete them."],"tags":["eslint","oxlint","dead-store","dataflow","unused-code"],"backgroundTag":"dead-store","analyzedSha":"1f902a69625cd14e6d8dc58feca94da099d2d251","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}