Conversation
super(true); | ||
} else { | ||
super(false); | ||
~~~~~ [0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one should be doable. This could result in many false positives in real world code.
The following would be more challenging and I don't know if we want to support code like that:
constructor() {
if (cond)
super(true);
if (!cond)
super(false);
}
And then there is this nasty but totally valid constructor:
constructor() {
if(cond)
return super(foo);
if(someOtherCondition)
return super(bar);
return super(baz);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the if
has a return
instead of else
? What if there's a switch
statement with break
?
TypeScript does control flow analysis, but as far as I can tell, there's no API for accessing it. But I would hate to add a bunch of exceptions that duplicate work done better by TypeScript itself.
} | ||
} | ||
|
||
[0]: 'super()' is used twice. It must be called only once. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would reword to something like: multiple calls to super() found. It must be called only once.
I don't think this should go in until it can use control flow analysis. There's going to be a lot of false positives. |
7e5797b
to
35d2c09
Compare
Added some minimal control flow analysis. Tell me if there are any test cases I missed. |
06aca5a
to
240b639
Compare
Not sure why the tests are failing. It only happens in one of the 4 containers. |
Container 3 tests against typescript 2.0.10. I don't know why there aren't any failures in the log, though. |
240b639
to
9903404
Compare
I rebased and it works now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
PR checklist
What changes did you make?
Added the
no-duplicate-super
rule, which warns ifsuper()
appears twice in a constructor.