Why is this an issue?

Both if-else chains and switch statements are used for conditional branching, but they differ in their syntax and the way they handle multiple conditions.

Having the same condition in both if-else chains and switch` cases can lead to unreachable code and a potential source of bugs. It defeats the purpose of conditional branching and can make the code harder to read and maintain.

if (event === 1) {
  openWindow();
} else if (event === 2) {
  closeWindow();
} else if (event === 1) {  // Noncompliant: Duplicated condition 'event === 1'
  moveWindowToTheBackground();
}

switch (event) {
  case 1:
    openWindow();
    break;
  case 2:
    closeWindow();
    break;
  case 1: // Noncompliant: Duplicated case '1'
    moveWindowToTheBackground();
    break;
}

Carefully review your conditions and ensure that they are not duplicated across the if-else chain or switch statement. Use distinct conditions and default blocks to cover all scenarios without redundant checks.

if (event === 1) {
  openWindow();
} else if (event === 2) {
  closeWindow();
} else if (event === 3) {
  moveWindowToTheBackground();
}

switch (event) {
  case 1:
    openWindow();
    break;
  case 2:
    closeWindow();
    break;
  case 3:
    moveWindowToTheBackground();
    break;
}

Resources

Documentation