no-single-statement-braces
WarningAutomatic fixWarningAutomatic fixWarningAutomatic fixDrop 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) { flush();}After ast-grep scan --update-all
if (ready) {if (ready) flush();}if (ready) { return; }After ast-grep scan --update-all
if (ready) { return; }if (ready) return;for (const item of items) { if (item.skip) { continue; } process(item);}After ast-grep scan --update-all
for (const item of items) { if (item.skip) { if (item.skip) continue; } process(item);}if (channel !== "dev") return "views://mainview/index.html";if (ready) { fn({ value: 1, });}if (ready) { // The queue drains on the next tick flush();}if (ready) { prepare(); flush();}if (ready) { if (queued) flush();}if (ready) { const value = load();}void run() { if (index < 0) { return; }}After ast-grep scan --update-all
void run() { if (index < 0) { return; } if (index < 0) return;}void run() { if (data != null) { setData(data); }}After ast-grep scan --update-all
void run() { if (data != null) { setData(data); } if (data != null) setData(data);}void run() { if (notification.metrics.pixels < notification.metrics.maxScrollExtent - scrollOffset) { return false; }}After ast-grep scan --update-all
void run() { if (notification.metrics.pixels < notification.metrics.maxScrollExtent - scrollOffset) { return false; } if (notification.metrics.pixels < notification.metrics.maxScrollExtent - scrollOffset) return false;}void run() { if (index < 0) return;}void run() { if (ready) { setData( data, ); }}void run() { if (ready) { prepare(); flush(); }}void run() { if (ready) { // The router needs the new data first flush(); }}void run() { if ((previous != null && previous[key] == null) || (next != null && next[key] == null)) { throw AssertionError("Key `$key` not found in JSON response"); }}class A { void run(boolean ready) { if (ready) { flush(); } }}After ast-grep scan --update-all
class A { void run(boolean ready) { if (ready) { if (ready) flush(); } }}class A { int run(int value) { if (value < 0) { return -1; } return 0; }}After ast-grep scan --update-all
class A { int run(int value) { if (value < 0) { if (value < 0) return -1; } return 0; }}class A { void run(boolean ready) { if (ready) { prepare(); flush(); } }}class A { void run(boolean ready) { if (ready) { // Keep this comment with the guarded call. flush(); } }}class A { void run(boolean ready) { if (ready) { flush( value ); } }}class A { void run(boolean ready) { if (ready) { if (queued) flush(); } }}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.
How to fix
When an if has no else and its only statement is on a single line, drop the braces and put the statement on the same line, as in if (index < 0) return;.
Keep the braces when the statement spans several lines, the block has a comment, or the joined line would pass 120 columns.
How to fix
Drop the braces if the if has no else and its only statement is on a single line.
Keep the braces when the statement spans several lines or the block has a comment.