if-else-if
chains JS-0034 46 $('.adjhide').hide();
47 $('.inrec-area').slideDown();
48 }
49 else if(selectedAdj == 'accu'){ 50 $('.adjhide').hide();
51 $('.accu-area').slideDown();
52 }
When an if-else-if
chain has identical conditions, a duplicate will evaluate the same true
or false
value as the identical expression earlier in the chain, meaning that its branch can never execute.
The issue can be autofixed by DeepSource by removing the duplicate if
statement and its code block.
This issue can be autofixed.
The fixer will remove the duplicate if
statement and its code block, for example, given the code sample having a duplicate if
condition:
if (a) {
func()
} else if (b) {
handler()
} else if (b) {
change()
}
The fixer will remove the later if
condition i.e, the one else if (b)
and its body, so the output will be
if (a) {
func()
} else if (b) {
handler()
}
if (isSomething(x)) {
func();
} else if (isSomething(x)) {
handler();
}
if (a) {
func();
} else if (b) {
handler();
} else if (c && d) {
change();
} else if (c && d) {
toggle();
} else {
cb();
}
if (n === 1) {
func();
} else if (n === 2) {
handler();
} else if (n === 3) {
change();
} else if (n === 2) {
toggle();
} else if (n === 5) {
cb();
}
if (isSomething(x)) {
func();
} else if (isSomethingElse(x)) {
handler();
}
if (a) {
func();
} else if (b) {
handler();
} else if (c && d) {
change();
} else if (c && e) {
toggle();
} else {
cb();
}
if (n === 1) {
func();
} else if (n === 2) {
handler();
} else if (n === 3) {
change();
} else if (n === 4) {
toggle();
} else if (n === 5) {
cb();
}