sindresorhus/eslint-plugin-unicorn
Rule proposal: `no-break-in-nested-loop`
クローズ
#1,055 opened on 2021/01/23
help wantednew rule
Repository metrics
- Stars
- (5,022 個のスター)
- PR merge metrics
- (平均マージ 4h 30m) (30d で 26 merged PRs)
説明
Actually, getting this because of auto-fix for no-array-for-each rule, it fix return in nested .forEach to continue.
It's not clear what to break/continue, when loop is nested.
Fail
for (const foo of bar) {
for (const baz of foo) {
// ...
break;
}
}
for (const foo of bar) {
while(foo.pop()) {
// ...
continue;
}
}
A even confusing case
for (const foo of bar) {
switch (foo) {
case 1:
// ...
break;
case 2:
// ...
continue;
}
}
Pass
function processFoo() {
for (const baz of foo) {
// ...
break;
}
}
for (const foo of bar) {
processFoo(foo)
}