{"record":{"id":"183598de672e7b02","repo":"oxc-project/oxc","slug":"empty-constructors-are-unnecessary","errorCode":null,"errorMessage":"Empty constructors are unnecessary","messagePattern":"Empty constructors are unnecessary","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs","lineNumber":18,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{\n        Argument, BindingPattern, CallExpression, Expression, FormalParameterRest,\n        FormalParameters, FunctionBody, MethodDefinition, Statement, TSAccessibility,\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\n/// ```js\n/// class A { constructor(){} }\n/// ```\nfn no_empty_constructor(constructor_span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Empty constructors are unnecessary\")\n        .with_label(constructor_span)\n        .with_help(\"Remove the constructor or add code to it.\")\n}\n\n/// ```js\n/// class A { }\n/// class B extends A {\n///     constructor() {\n///         super();\n///     }\n/// }\n/// ```\nfn no_redundant_super_call(constructor_span: Span, super_span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Redundant super call in constructor\")\n        .with_labels([\n            constructor_span.primary_label(\"This constructor is unnecessary,\"),\n            super_span.label(\"because it only passes arguments through to the superclass\"),\n        ])","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs#L1-L36","documentation":"Diagnostic from `no-useless-constructor` (empty-constructor variant). A class declares `constructor() {}` with no parameters and no body statements. Such a constructor is identical to the default constructor the spec supplies, so it is dead code. Oxc reports the constructor span with help 'Remove the constructor or add code to it.'","triggerScenarios":"`class A { constructor() {} }` or `constructor() { /* only comments */ }`. Fires on ClassElement constructors whose body is empty; derived classes whose body is only `super(...)` are handled by the separate redundant-super diagnostic.","commonSituations":"Scaffolding from class boilerplate templates; refactors that removed initialization code but left the shell; TypeScript code where `public x: number` parameter properties were converted to fields.","solutions":["Delete the empty constructor entirely; the class works the same via its implicit default constructor.","If you intended real initialization, add the missing statements to the body.","Apply the fix automatically with `oxlint --fix`.","Keep it only if a decorator or mixin framework requires an explicit constructor, and disable the rule for that line."],"exampleFix":"// before\nclass A {\n  constructor() {}\n}\n\n// after\nclass A {}","handlingStrategy":"validation","validationCode":"class A {\n  constructor() {}\n}\n// check: does the constructor body have zero statements? then delete it","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not write constructors until you add real initialization.","Prefer class fields (`class A { x = 1; }`) over constructor assignment.","Delete scaffold constructors from templates before committing."],"tags":["lint","eslint","oxlint","class","constructor"],"backgroundTag":"no-useless-constructor","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"}