{"record":{"id":"8ce47a10937a4d3e","repo":"oxc-project/oxc","slug":"expected-to-always-call-super-before-this-s","errorCode":null,"errorMessage":"Expected to always call `super()` before `this`/`super` property access.","messagePattern":"Expected to always call `super\\(\\)` before `this`/`super` property access\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/eslint/no_this_before_super.rs","lineNumber":18,"sourceCode":"use oxc_ast::{\n    AstKind, AstType,\n    ast::{Argument, Expression, MethodDefinitionKind},\n};\nuse oxc_cfg::{\n    BlockNodeId, ControlFlowGraph, EdgeType, ErrorEdgeKind,\n    graph::visit::{EdgeRef, neighbors_filtered_by_edge_weight},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::NodeId;\nuse oxc_span::{GetSpan, Span};\nuse rustc_hash::{FxHashMap, FxHashSet};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_this_before_super_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Expected to always call `super()` before `this`/`super` property access.\")\n        .with_help(\"Call `super()` before `this`/`super` property access.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoThisBeforeSuper;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Requires calling `super()` before using `this` or `super`.\n    ///\n    /// This rule can be disabled for TypeScript code, as the TypeScript compiler\n    /// enforces this check.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// In the constructor of derived classes, if `this`/`super` are used before `super()` calls,","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_this_before_super.rs#L1-L36","documentation":"`no-this-before-super` reports accessing `this` or `super` properties in a derived class constructor before `super()` has been called — JavaScript throws `ReferenceError: Must call super constructor in derived class before accessing 'this'` at runtime in exactly this situation. oxlint implements it with control-flow-graph analysis (oxc_semantic CFG, `neighbors_filtered_by_edge_weight`, ErrorEdgeKind) so both straight-line orderings and branches (e.g. `if (x) { this.a = 1 } super();`) are covered.","triggerScenarios":"`class A extends B { constructor() { this.x = 1; super(); } }`, calling `super.method()` or reading `this` in any CFG path that reaches the access before the `super()` call node, including inside conditionals or early-return paths.","commonSituations":"Adding initialization code at the top of a derived constructor and forgetting `super()` must come first; refactoring constructors and moving the `super(...)` call into a branch; subclassing framework base classes (React components, custom elements) where the super call is easy to overlook.","solutions":["Move the `super(...)` call to the first statement of the constructor.","If the access is conditional, ensure every path reaching it has already called `super()` (hoist the super call above the branch).","Delete the field initialization from the constructor and use a class field declaration instead — fields initialize after super() automatically."],"exampleFix":"// before\nclass Btn extends Component {\n  constructor(props) {\n    this.label = props.label; // ReferenceError at runtime\n    super(props);\n  }\n}\n\n// after\nclass Btn extends Component {\n  constructor(props) {\n    super(props);\n    this.label = props.label;\n  }\n}","handlingStrategy":"validation","validationCode":"# TypeScript also catches this before runtime: 'super' must be called before accessing 'this'\nnpx tsc --noEmit","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make super() the first statement of every derived constructor, always.","Prefer class field declarations over constructor assignments in subclasses.","Never read this or super inside helper functions called before super() completes."],"tags":["eslint","oxlint","no-this-before-super","classes","inheritance","constructor","control-flow"],"backgroundTag":"this-before-super","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"}