Skip to main content

no-equal-nested-conditions

added in: 1.7.0
Pro+
preset: recommended

Warns when an if statement contains another if statement with the same condition.

Example

❌ Bad:

if (value == 1) {
// LINT: Avoid duplicate conditions in nested 'if/else if'. Try replacing the duplicate condition or removing it.
if (value == 1) {
...
}
}

if (value == 1) {
...

// LINT: Avoid duplicate conditions in nested 'if/else if'. Try replacing the duplicate condition or removing it.
if (value == 1) {
...
}
}

✅ Good:

if (value != 1) {
if (value == 1) { // Correct, different condition
...
}
}

if (value != 1) {
...

if (value == 1) {
...
}
}

Additional Resources