Skip to contentSlop Block

no-single-statement-braces

WarningAutomatic fix

Drop braces around a single-line statement when the if has no else. TypeScript puts the statement on the next line; Dart and Java keep it on the same line. ast-grep scan --update-all fixes it.

if (ready) {Remove the braces around this single statement	flush();}

After ast-grep scan --update-all

if (ready) {if (ready)	flush();}
if (ready) { return; }Remove the braces around this single statement

After ast-grep scan --update-all

if (ready) { return; }if (ready) return;
for (const item of items) {	if (item.skip) {Remove the braces around this single statement		continue;	}	process(item);}

After ast-grep scan --update-all

for (const item of items) {	if (item.skip) {	if (item.skip)		continue;	}	process(item);}
// ast-grep-ignore: no-single-statement-braces-typescript

How to fix

Drop the braces if the if has no else and its only statement is on a single line. Put the statement on the next line.

Keep the braces when the statement spans several lines or the block has a comment. Return and throw statements must start on the line after the condition.