Rules / Suspicious / empty-statements
empty-statements
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.
Invalid
example.dartdart
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');
}
Unnecessary empty statement — remove the `;` or replace it with a block
Unnecessary empty statement — remove the `;` or replace it with a block
Unnecessary empty statement — remove the `;` or replace it with a block
10void f3(bool x) {
11 while (x) ;
∙
Unnecessary empty statement — remove the `;` or replace it with a block
14void f4() {
15 for (var i = 0; i < 1; i++) ;
∙
Unnecessary empty statement — remove the `;` or replace it with a block
18void f5(bool x) {
19 if (x) ;
∙
Unnecessary empty statement — remove the `;` or replace it with a block
Valid
example.dartdart
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');
}
How to configure
Set the severity of empty-statements in your falcon.json:
falcon.jsonjson
{
"linter": {
"rules": {
"suspicious": {
"empty-statements": "error"
}
}
}
}