Skip to content

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

@michaelficarra

Description

@michaelficarra

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.

Metadata

Metadata

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionenhancementThis change enhances an existing feature of ESLintruleRelates to ESLint's core rules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions