empty-statements

Same as empty_statements in Dart lints

Path
lint/suspicious/empty-statements
Default
On (recommended)
Origin
Dart lints
Rule
231 of 512
recommended

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

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');
}
Remove the unnecessary `;` or replace it with a block.
1void f1() {
2 ;
Remove the unnecessary `;` or replace it with a block.
6 print('x');
7 ;
Remove the unnecessary `;` or replace it with a block.
10void f3(bool x) {
11 while (x) ;
Remove the unnecessary `;` or replace it with a block.
14void f4() {
15 for (var i = 0; i < 1; i++) ;
Remove the unnecessary `;` or replace it with a block.
18void f5(bool x) {
19 if (x) ;
Remove the unnecessary `;` or replace it with a block.
23 print('a');
24 ;

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

Configure empty-statements

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "suspicious": {
        "empty-statements": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/suspicious/empty-statements: <reason>
  • no-duplicate-case-valuesno_duplicate_case_valuesrecommended

    Flags semantically equal constant values within one switch.

  • no-empty-blockno-empty-block

    Flags empty blocks ({}).

  • no-equal-argumentsno-equal-arguments

    Flags an argument passed more than once in the same invocation.

  • no-equal-then-elseno-equal-then-elserecommended

    Flags an if/else or ternary whose two branches are identical.

  • no-magic-string

    Extract inline string literals into named variables or constants.

  • no-self-comparisonsno_self_comparisonsrecommended

    Flags proven self-comparisons of side-effect-free scalar values.

  • no-wildcard-variable-usesno_wildcard_variable_usesrecommended

    Flags references to a wildcard variable or parameter (a name made solely of underscores, such as _ or __).

  • overridden-fieldsoverridden_fieldsrecommended

    Flags instance fields that redeclare an inherited field.