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

Add no-unnecessary-qualifier rule #2008

Merged
merged 5 commits into from Jan 16, 2017

Conversation

andy-hanson
Copy link
Contributor

PR checklist

What changes did you make?

Added the no-unnecessary-qualifier rule, which warns for A.x if just x would have the same meaning.

@andy-hanson andy-hanson force-pushed the no_unnecessary_qualifier branch 2 times, most recently from b044d1a to 33638ff Compare January 8, 2017 20:23
@@ -111,6 +111,10 @@ export class Replacement {
return replacements.reduce((text, r) => r.apply(text), content);
}

public static deleteFromTo(start: number, end: number): Replacement {
Copy link
Contributor

Choose a reason for hiding this comment

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

use the one in ruleWalker.ts

@nchen63
Copy link
Contributor

nchen63 commented Jan 14, 2017

@andy-hanson @adidahiya how about naming this shortest-qualifier?

@andy-hanson
Copy link
Contributor Author

The rule is about notifying you that a certain node in your AST can be removed if it's unnecessary. It doesn't measure the length of anything.
If you had a rule that warned on !!x (where x is of type boolean), you wouldn't call it shortest-boolean-expression, you'd call it no-unnecessary-bang-bang, right?
Open to name changes, but shortest implies that it compares multiple possible qualifiers for length.

@nchen63
Copy link
Contributor

nchen63 commented Jan 14, 2017

My concern is that no-unnecessary-qualifier sounds like a binary rule, like either have a qualifier or don't have a qualifier. For example, if you're in the a.b.c namespace, it would only warn if the qualifier exactly matches a.b.c. Maybe it's because I don't view a as a qualifier for b.c (but should?) I don't feel that strongly about changing the name either way.

@andy-hanson
Copy link
Contributor Author

In my case, I'm just trying to eliminate single qualifiers -- X.foo in namespace X.
But in #1987 there were multiple qualifiers and a few, but not all, could be removed.

I can see how no-unnecessary-qualifier sounds like it does nothing for the latter case. But shortest-qualifier sounds like it does nothing for the former case.

Will think about this later.

@ajafff
Copy link
Contributor

ajafff commented Jan 14, 2017

This should work for enum too. At least the name implies that. Don't know if it does already, but there is no test for it.

enum Foo {
    Bar, 
    Baz = Foo.Bar // could be written as Baz = Bar
}

@nchen63 nchen63 merged commit 1410020 into palantir:master Jan 16, 2017
@nchen63
Copy link
Contributor

nchen63 commented Jan 16, 2017

@andy-hanson thanks! name is ok

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

Successfully merging this pull request may close these issues.

None yet

3 participants