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

org.sonar.l10n.py.rules.python.S5797.html Maven / Gradle / Ivy

The newest version!

This rule raises an issue when a constant expression is used as a condition in an if, elif, a conditional expression or other boolean expressions.

Why is this an issue?

When a constant is used as a condition, either it has no effect on the execution flow and it can be removed, or some code will never be executed and it is a bug.

Code examples

Noncompliant code example

def foo():
    a = True
    if a: # Noncompliant: the condition is always true
      return 1
    else:
      return 2

Compliant solution

def foo():
    a = bar()
    if a:
      return 1
    else:
      return 2

Resources

Documentation





© 2015 - 2025 Weber Informatics LLC | Privacy Policy