The if
and else
statements should not be used inline. Instead, use a block statement.
Apply with the Grit CLI
grit apply no_inline_if
Examples
BEFORE
if (condition) doSomething(); else doSomethingElse();
AFTER
if (condition) { doSomething(); } else { doSomethingElse(); }
Good
JAVASCRIPT
if (condition) { doSomething(); } else { doSomethingElse(); }
If by itself
This pattern only targets if
statements that are followed by an else
statement. If the if
statement is by itself, it is not affected.
JAVASCRIPT
if (condition) doSomething();