We got “s6647 - Unnecessary constructors should be removed” code smell when we use an abstract parent class with protected constructor.
I think that it is a false positive report because the code cannot be built without these constructors.
can you develop further what you mean by “Cannot be built”? If it’s due to the protected constructor of the parent class, you can provide a factory method?
abstract class Parent {
protected constructor(
private x: number
) {
}
}
class Child extends Parent {
static createChild() {
return new Child(0);
}
}
const child = Child.createChild();
The constructor of the child class is not needed when the implementation is empty. The only reason your code cannot be built in the given example is that the parent constructor is protected, right? Can you further develop your point?
I’m not saying this is not an FP, but would like to further understand the reasoning. I understand also that providing a factory is less preferable than an empty constructor.