Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow negated condition in for-in guards in guard-for-in rule #7567

Closed
michaelficarra opened this issue Nov 8, 2016 · 11 comments · May be fixed by ali8889/emerald-wallet#4, guru2088/tokeno#3, DmytroSkrypnyk/test_bootstrap#6 or ali8889/emerald-wallet#17

Comments

@michaelficarra
Copy link
Member

@michaelficarra michaelficarra commented Nov 8, 2016

I would like guard-for-in to allow the following pattern in addition to what it currently allows.

for (key in foo) {
    if (!{}.hasOwnProperty.call(foo, key)) continue;
    doSomething(key);
}

To be clear, the difference is that this guard has a negated condition with a continue as the consequent. The continue should be allowed as the only statement in a block as well, to be compatible with that brace style preference.

for (key in foo) {
    if (!{}.hasOwnProperty.call(foo, key)) {
        continue;
    }
    doSomething(key);
}

edit:

What rule do you want to change?

guard-for-in

Does this change cause the rule to produce more or fewer warnings?

Fewer.

How will the change be implemented? (New option, new default behavior, etc.)?

New default behaviour.

Please provide some example code that this change will affect:

for (key in foo) {
    if (!{}.hasOwnProperty.call(foo, key)) continue;
    doSomething(key);
}
for (key in foo) {
    if (!{}.hasOwnProperty.call(foo, key)) {
        continue;
    }
    doSomething(key);
}

What does the rule currently do for this code?

Warns.

What will the rule do after it's changed?

Not warn.

@platinumazure
Copy link
Member

@platinumazure platinumazure commented Nov 8, 2016

Maybe this should be refactored to use code path analysis, so that we could flag the for statement if any path is reachable without having gone through a hasOwnProperty check. Of course, it doesn't help that right now we're not even checking what the IfStatement test looks like...

👍 from me.

@platinumazure
Copy link
Member

@platinumazure platinumazure commented Nov 8, 2016

Oh, @michaelficarra, can you please edit your post to match this template? Thanks!

@michaelficarra
Copy link
Member Author

@michaelficarra michaelficarra commented Nov 8, 2016

@platinumazure Done.

@not-an-aardvark
Copy link
Member

@not-an-aardvark not-an-aardvark commented Jul 11, 2017

@michaelficarra Are you still interested in pushing this proposal forward?

@michaelficarra
Copy link
Member Author

@michaelficarra michaelficarra commented Jul 11, 2017

@not-an-aardvark Yes. What does that involve?

@not-an-aardvark
Copy link
Member

@not-an-aardvark not-an-aardvark commented Jul 11, 2017

It generally involves drumming up support from the team (see here). Right now there are two 👍s from team members on the proposal, so we would need one more for the proposal to be accepted.

@michaelficarra
Copy link
Member Author

@michaelficarra michaelficarra commented Jul 11, 2017

@not-an-aardvark Does my own 👍 count?

@not-an-aardvark
Copy link
Member

@not-an-aardvark not-an-aardvark commented Jul 11, 2017

No, it does not (it requires three 👍s in addition to a champion).

ccing @eslint/eslint-team (sorry about all the pings today) to see if anyone else is in favor of this.

@platinumazure
Copy link
Member

@platinumazure platinumazure commented Dec 31, 2017

We don't have a champion on this, so I'm setting this back to evaluating. If we don't get a champion in a week or two, we should probably close this.

@ilyavolodin
Copy link
Member

@ilyavolodin ilyavolodin commented Jan 4, 2018

@platinumazure Since @michaelficarra created this issue, and filed a PR, I assume he is championing it, so setting it back to accepted.

@platinumazure
Copy link
Member

@platinumazure platinumazure commented Jan 4, 2018

@ilyavolodin @michaelficarra Sorry for the mixup!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.