All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.SwitchWithoutDefault.html Maven / Gradle / Ivy

The requirement for a final default clause is defensive programming. This clause should either take appropriate action or contain a suitable comment as to why no action is taken.

The following code snippet illustrates this rule:

switch (param) { // Non-Compliant - default clause is missing
  case 0:
    doSomething();
    break;
  case 1:
    doSomethingElse();
    break;
}

switch (param) {
  default: // Non-Compliant - default clause should be the last one
    doSomething();
    break;
  case 0:
    doSomethingElse();
    break;
}

switch (param) {
  case 0:
    doSomethingElse();
    break;
  default: // Compliant
    doSomethingElse();
    break;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy