Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Add no-duplicate-super #2038

Merged
merged 2 commits into from Jan 29, 2017
Merged

Conversation

andy-hanson
Copy link
Contributor

PR checklist

What changes did you make?

Added the no-duplicate-super rule, which warns if super() appears twice in a constructor.

super(true);
} else {
super(false);
~~~~~ [0]
Copy link
Contributor

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);

Copy link
Contributor Author

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.
Copy link
Contributor

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.

@nchen63
Copy link
Contributor

nchen63 commented Jan 18, 2017

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.

@andy-hanson andy-hanson force-pushed the no_duplicate_super branch 2 times, most recently from 7e5797b to 35d2c09 Compare January 21, 2017 22:01
@andy-hanson
Copy link
Contributor Author

Added some minimal control flow analysis. Tell me if there are any test cases I missed.

@andy-hanson andy-hanson force-pushed the no_duplicate_super branch 2 times, most recently from 06aca5a to 240b639 Compare January 21, 2017 23:02
@andy-hanson
Copy link
Contributor Author

Not sure why the tests are failing. It only happens in one of the 4 containers.

@nchen63
Copy link
Contributor

nchen63 commented Jan 22, 2017

Container 3 tests against typescript 2.0.10. I don't know why there aren't any failures in the log, though.

@andy-hanson
Copy link
Contributor Author

I rebased and it works now.

Copy link
Contributor

@nchen63 nchen63 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants