avoid-empty-else
Same as avoid_empty_else in Dart lints
- Group
- Suspicious
- Path
lint/suspicious/avoid-empty-else- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 59 of 512
Flags an else clause whose body is an empty statement (else ;).
An else immediately followed by a semicolon binds that empty statement as
the whole else branch, so the block meant to run instead executes
unconditionally right after the if. This is nearly always a stray semicolon
typed between else and the intended { ... }. Remove the semicolon so the
following block becomes the else body, or delete the else entirely if no
alternative branch is needed.
Invalid
void f1(bool a) {
if (a) {
print('a');
} else ;
}
void f2(int n) {
if (n > 0) print('pos'); else ;
}
void f3(bool a) {
if (a) {
print('a');
} else
;
}
void f4(bool a, bool b) {
if (a) {
print('a');
} else if (b) {
print('b');
} else ;
}
void f5(bool a) {
while (a) {
if (a) {
print('x');
} else ;
}
}
void f6(bool a) {
if (a) print('y'); else ;
} print('a'); } else ;void f2(int n) { if (n > 0) print('pos'); else ; } else ; print('b'); } else ; print('x'); } else ;void f6(bool a) { if (a) print('y'); else ;Valid
void g1(bool a) {
if (a) {
print('a');
} else {
print('b');
}
}
void g2(int n) {
if (n > 0) {
print('pos');
}
}
void g3(bool a, bool b) {
if (a) {
print('a');
} else if (b) {
print('b');
} else {
print('c');
}
}
void g4(bool a) {
if (a) print('y');
}
void g5(bool a) {
if (a) {
print('a');
}
}
void g6(bool a) {
while (a) {
if (a) {
print('x');
} else {
print('y');
}
}
}Configure avoid-empty-else
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"avoid-empty-else": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/avoid-empty-else: <reason>More suspicious rules
- avoid-ignoring-return-values
avoid-ignoring-return-valuesFlags a discarded call whose resolved return type is non-void.
- avoid-incorrect-uri
Reject runtime-invalid Uri constructor arguments: conflicting path or query inputs and query parameter values that are neither null, strings nor iterables of strings.
- avoid-inverted-boolean-checks
Prefer direct equality comparisons and De Morgan forms in control-flow conditions.
- avoid-multi-assignment
Split chained assignments into separate statements.
- avoid-mutating-parameters
Detects writes through named function, method and constructor parameter objects.
- avoid-negated-conditions
Prefer positive conditions when both branches can be swapped.
- avoid-nested-assignments
Require assignments to be standalone statements, arrow bodies or loop operations.
- avoid-non-final-exception-class-fields
Exception and Error payloads should not change after construction.