switch statement should not have duplicate case clauses

  • DUPLICATE_CASE
  • Error
  • Medium
  • No tags

This rule applies when switch statement has duplicate case clauses.

Later clause is ignored and it is likely that a programmer copied a clause but forgot to change.

Noncompliant Code Example

switch (x) {
case '1':
    e += 'case';
    break;
case '1': // DUPLICATE_CASE alarm
    e += 'another case';
    break;
}

Compliant Code Example

switch (x) {
case '1':
    e += 'case';
    break;
case '2':
    e += 'another case';
    break;
}

Version

This rule was introduced in DeepScan 1.0.0-alpha.