No inline `if` and `else` statements

JavaScript pattern

The if and else statements should not be used inline. Instead, use a block statement.

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();