This rule makes sure that every if statement ends with an else statement. else if (/*test*/) {}
does not count as an else statement.
// valid
if (a === 'foo') {
a = 'bar';
} else {
a = 'else';
}
// invalid
if (a === 'foo') {
a = 'bar';
}
// valid
if (a === 'foo') {
a = 'bar';
} else if (a === 'bar') {
a = 'hello';
} else {
a = 'world';
}
// invalid
if (a === 'foo') {
a = 'bar';
} else if (a === 'bar') {
a = 'hello';
}
// valid
if (a === 'foo')
a = 'bar';
else
b = 'hello world';
// invalid
if (a === 'foo')
a = 'bar';