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

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

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

Jump statements, such as return, break and continue, are used to change the normal flow of execution in a program. They are useful because they allow for more complex and flexible code. However, it is important to use jump statements judiciously, as overuse or misuse can make code difficult to read and maintain.

Jump statements are redundant when they do not affect the program flow or behavior.

function redundantJump(x) {
  if (x == 1) {
    console.log("x == 1");
    return; // Noncompliant: The function would return 'undefined' also without this 'return' statement
  }
}

Remove any jump statements that are unnecessary or redundant.

function redundantJump(x) {
  if (x == 1) {
    console.log("x == 1");
  }
}

Exceptions

  • break and return inside switch statements are ignored, because they are often used for consistency.
  • continue associated with a label is ignored, because it is usually used for clarity.
  • Jump statements are ignored when they are the only statement inside a block.

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy