Skip to content

Latest commit

 

History

History
47 lines (40 loc) · 677 Bytes

File metadata and controls

47 lines (40 loc) · 677 Bytes

Enforce every if has an else (if-else)

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';