sindresorhus/eslint-plugin-unicorn

Rule proposal: `no-break-in-nested-loop`

Geschlossen

#1.055 geöffnet am 23.01.2021

 (5 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)JavaScript (468 Forks)user submission
help wantednew rule

Repository-Metriken

Stars
 (5.022 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 4h 30m) (26 gemergte PRs in 30 T)

Beschreibung

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

Contributor Guide