avoid-unconditional-break
- Group
- Correctness
- Path
lint/correctness/avoid-unconditional-break- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 152 of 512
Reports unconditional break, continue, return or throw in a for-loop body.
Branches, nested loops, try/finally, and labeled jumps are not flattened: they may change which iteration or construct an exit interrupts.
Invalid
void exits(Iterable<int> values) {
for (final value in values) { print(value); break; }
for (final value in values) { print(value); continue; }
for (final value in values) { print(value); return; }
for (final value in values) { throw value; }
for (var i = 0; i < 10; i++) { final value = i; print(value); break; }
}
void bare(Iterable<int> values) {
for (final value in values) continue;
}void exits(Iterable<int> values) { for (final value in values) { print(value); break; } for (final value in values) { print(value); break; } for (final value in values) { print(value); continue; } for (final value in values) { print(value); continue; } for (final value in values) { print(value); return; } for (final value in values) { print(value); return; } for (final value in values) { throw value; } for (final value in values) { throw value; } for (var i = 0; i < 10; i++) { final value = i; print(value); break; }void bare(Iterable<int> values) { for (final value in values) continue;Valid
void repeat(bool stop) {
for (var i = 0; i < 10; i++) { if (stop) break; }
while (stop) { if (stop) continue; break; }
for (var i = 0; i < 3; i++) { print(i); }
do { if (stop) break; } while (stop);
outer: for (;;) { break outer; }
for (var i = 0; i < 3; i++) {
switch (i) { case 0: break; default: print(i); }
}
while (stop) {
try { break; } finally { if (stop) continue; }
}
}Configure avoid-unconditional-break
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"avoid-unconditional-break": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/avoid-unconditional-break: <reason>More correctness rules
- avoid-undisposed-instancesrecommendedflutter
Warns when a disposable constructor result is discarded.
- avoid-unmodified-loop-conditionrecommended
Flags loop conditions whose local scalar inputs are never modified by the loop.
- avoid-unnecessary-setstaterecommendedflutter
Avoid setState during build, initState, or didUpdateWidget.
- avoid-unnecessary-stateful-widgetsrecommendedflutter
Warns when a
StatefulWidget's local State contains only a pure build method. - avoid-unreachable-for-loop
Reports iteration of a collection in a branch that requires it to be empty.
- avoid-unrelated-type-castsrecommended
Flags casts between types proven unrelated by canonical type resolution.
- avoid-unsafe-collection-methods
Flags potentially throwing element access on SDK collections.
- avoid-unsafe-reduce
Warn when SDK Iterable.reduce can receive an empty collection.