A constructor does only what the implicit one would
What it finds
constructor() {} without parameters in a class without a parent, or constructor(a, b) { super(a, b); } in one with: a constructor that does exactly what the implicit one would can go.
Constructors with modifiers such as private or protected, which change who may create instances, with decorators, with parameter properties or with overload signatures are left alone; so are those in a class with a parent whose parameters have type annotations, which may narrow the parent's signature, or that carry a documentation comment, which describes what the parent accepts. The fix removes the constructor. It is safe in a class without a parent; in one with a parent it is not, because the implicit constructor passes on every argument, not only the declared ones.
From the rule's source, constructor_adds_nothing.rs.
class Base { constructor(public id: number) {}}class Plain { constructor() {}tx0 reports: this constructor does nothing the implicit one would not}class Child extends Base { constructor(id) {tx0 reports: this constructor does nothing the implicit one would not super(id); }}class Rest extends Base { constructor(...args) {tx0 reports: this constructor does nothing the implicit one would not super(...args); }}class Narrowed extends Base { constructor(id: 1 | 2) { super(id); }}class Hidden { private constructor() {}}class Prop { constructor(readonly name: string) {}}class Documented extends Base { /** Takes the id of a stored record. */ constructor(id) { super(id); }}class Overloaded extends Base { constructor(id: number); constructor(id) { super(id); }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:constructor-adds-nothing" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:constructor-adds-nothing] reason="..."tx0 explain tx0/ts:constructor-adds-nothing shows the same in the terminal. Found a false positive? Report it.