@@ -19,6 +19,7 @@ import { isConstructorDeclaration, isParameterProperty } from "tsutils";
1919import * as ts from "typescript" ;
2020
2121import * as Lint from "../index" ;
22+ import { Replacement } from "../language/rule/rule" ;
2223
2324export class Rule extends Lint . Rules . AbstractRule {
2425 public static metadata : Lint . IRuleMetadata = {
@@ -55,15 +56,28 @@ const isAccessRestrictingConstructor = (node: ts.ConstructorDeclaration): boolea
5556 // If this has any modifier that isn't public, it's doing something
5657 node . modifiers . some ( modifier => modifier . kind !== ts . SyntaxKind . PublicKeyword ) ;
5758
59+ const containsDecorator = ( node : ts . ConstructorDeclaration ) : boolean =>
60+ node . parameters . some ( p => p . decorators !== undefined ) ;
61+
5862function walk ( context : Lint . WalkContext ) {
5963 const callback = ( node : ts . Node ) : void => {
6064 if (
6165 isConstructorDeclaration ( node ) &&
6266 isEmptyConstructor ( node ) &&
6367 ! containsConstructorParameter ( node ) &&
68+ ! containsDecorator ( node ) &&
6469 ! isAccessRestrictingConstructor ( node )
6570 ) {
66- context . addFailureAtNode ( node , Rule . FAILURE_STRING ) ;
71+ const replacements = [ ] ;
72+ // Since only one constructor implementation is allowed and the one found above is empty, all other overloads can be safely removed.
73+ for ( const maybeConstructor of node . parent . members ) {
74+ if ( isConstructorDeclaration ( maybeConstructor ) ) {
75+ replacements . push (
76+ Replacement . deleteFromTo ( maybeConstructor . pos , maybeConstructor . end ) ,
77+ ) ;
78+ }
79+ }
80+ context . addFailureAtNode ( node , Rule . FAILURE_STRING , replacements ) ;
6781 } else {
6882 ts . forEachChild ( node , callback ) ;
6983 }
0 commit comments