empty-statements
Same as empty_statements in Dart lints
- Group
- Suspicious
- Path
lint/suspicious/empty-statements- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 231 of 512
Flags stray empty statements (a lone ;).
A solitary semicolon does nothing, and where it slips in it usually changes
meaning: while (cond); turns the following block into an unconditional body,
and a stray ; after an if header detaches the intended branch. It is
almost always an accidental extra semicolon or a loop body that should have
been a block. Remove it, or replace it with the block that was intended. The
semicolons in a for (;;) header are loop syntax, not statements, and are
never reported. A real null; expression statement is not an empty statement.
This includes empty statements inside anonymous functions.
Invalid
void f1() {
;
}
void f2() {
print('x');
;
}
void f3(bool x) {
while (x) ;
}
void f4() {
for (var i = 0; i < 1; i++) ;
}
void f5(bool x) {
if (x) ;
}
void f6() {
print('a');
;
print('b');
}void f1() { ; print('x'); ;void f3(bool x) { while (x) ;void f4() { for (var i = 0; i < 1; i++) ;void f5(bool x) { if (x) ; print('a'); ;Valid
void g1() {
print('x');
}
void g2(bool x) {
while (x) {
print('loop');
}
}
void g3() {
for (var i = 0; i < 1; i++) {
print(i);
}
}
void g4(bool x) {
if (x) {
print('yes');
}
}
void g5() {
var a = 1;
var b = 2;
print(a + b);
}
void g6() {
print('a');
print('b');
}Configure empty-statements
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"empty-statements": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/empty-statements: <reason>More suspicious rules
- no-duplicate-case-values
no_duplicate_case_valuesrecommendedFlags semantically equal constant values within one switch.
- no-empty-block
no-empty-blockFlags empty blocks (
{}). - no-equal-arguments
no-equal-argumentsFlags an argument passed more than once in the same invocation.
- no-equal-then-else
no-equal-then-elserecommendedFlags an
if/elseor ternary whose two branches are identical. - no-magic-string
Extract inline string literals into named variables or constants.
- no-self-comparisons
no_self_comparisonsrecommendedFlags proven self-comparisons of side-effect-free scalar values.
- no-wildcard-variable-uses
no_wildcard_variable_usesrecommendedFlags references to a wildcard variable or parameter (a name made solely of underscores, such as
_or__). - overridden-fields
overridden_fieldsrecommendedFlags instance fields that redeclare an inherited field.