Skip to content

no-empty-statement

C#suspiciousfix: safedefault: offcsharp/stylecop

Reports a lone ; that does nothing. A statement labelled label: ; is not reported. The fix removes the statement (its whole line when it is alone on it), or turns an empty loop or if body into { }; it is not offered for the only statement of a switch section. The compiler reports if (x); too.

A stray ; is usually the result of a typo or an edit. After if (x); or while (x); it is the body of the statement, so the line that follows runs unconditionally, whatever its indentation says.

To fix, delete the ;, or write { } for a body that is meant to be empty.

Reported
class A { void F(bool x, int y) {
;
if (x); else { }
...
switch (y) { case 1: ; break; default: ; }
L: ;
int z = 1;;
} }
csharp:
lint:
rules:
no-empty-statement: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line no-empty-statement in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1106 full