Remove-Redundant-If-Statement¶
Sourcery rule id: remove-redundant-if-statement
¶
Description¶
Remove an if
statement where the condition is true
.
Before¶
if (true) {
console.log("great!")
}
After¶
console.log("great!")
Explanation¶
If the condition of an if
statement is true
, its body will always be executed. Conversely, if the condition
is always false
, then its body will never be executed. In the first case, we can replace the if
statement with
its body, and in the second case we can remove it altogether.