Skip to content

Remove-Redundant-If-Statement

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Sourcery rule id: remove-redundant-if-statement

Section titled “Sourcery rule id: remove-redundant-if-statement”

Remove an if statement where the condition is true.

if (true) {
console.log("great!")
}
console.log("great!")

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.