This is an issue when a conditional expression contains multiple range checks on the same variable, and one of those checks is already implied by another more restrictive check.
When you write conditional expressions with multiple range checks, each condition should add meaningful information about the valid range. However, sometimes one condition is already guaranteed to be true based on another condition in the same expression.
For example, if you check that x >= 5, you don’t also need to check that x >= 0 because any number greater than or
equal to 5 is automatically greater than or equal to 0. The second check is redundant - it doesn’t add any new information.
Redundant range checks create several problems:
These issues don’t cause runtime errors, but they make the codebase harder to work with and more prone to bugs during maintenance.
This issue affects code maintainability and readability. While it doesn’t cause functional bugs or security vulnerabilities, it makes the code harder to understand and modify correctly. Developers may waste time trying to understand why both conditions exist, or they may introduce inconsistencies when updating the logic.
Remove the redundant condition from the expression, keeping only the more restrictive check. When one condition implies another, keep the one that defines the actual boundary you care about.
if (x >= 0 && x >= 5 && x <= 100) { // Noncompliant
// Process x in range [5, 100]
}
if (x >= 5 && x <= 100) {
// Process x in range [5, 100]
}