Skip to content

no-dupe-case

Forbid duplicate case in switch statements

INFO

☑️ The predefined configuration "mslint:recommended" enables this rule.

Rule details

This rule prohibits duplicate case conditions in switch statements.

Example of incorrect code for this rule:

maniascript
main() {
  switch (A) {
    case 1: {}
    case 1: {} // 1 already catched above
    case 2, 3: {}
    case 3: {} // 3 already catched above
    case 1, 2, 3, 4: {} // 1, 2 and 3 already catched above
    case 4, 1, 2: {} // 4, 1 and 2 already catched above
    case 1+1: {}
    case     1  +   1     : {} // 1 + 1 already catched above
    case 5, 6, 5, 6: {} // 5 and 6 already catched in the same case
  }
}

Example of correct code for this rule:

maniascript
main() {
  switch (A) {
    case 1: {}
    case 2, 3: {}
    case 4: {}
    case 1+1: {}
    case 5, 6: {}
  }
}

Resources