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

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

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

In a for loop, the update clause is responsible for modifying the loop counter variable in the appropriate direction to control the loop’s iteration. It determines how the loop counter variable changes with each iteration of the loop. The loop counter should move in the right direction to prevent infinite loops or unexpected behavior.

This rule raises an issue when the loop counter is updated in the wrong direction with respect to the loop termination condition.

for (let i = 0; i < strings.length; i--) { // Noncompliant: The counter 'i' is decremented, making the loop infinite
  //...
}

To ensure the for loop behaves as expected, you should specify the correct update clause that moves the loop counter in the right direction based on the loop’s logic and desired outcome.

for (let i = 0; i < strings.length; i++) {
  //...
}

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy