Why this matters
Mixing return statements that return values with those that don’t can lead to confusing, unpredictable behavior.
return ConsistentlyDetect functions that mix return statements with values and those without. Inconsistent return usage can lead to unpredictable behavior.
Mixing return statements that return values with those that don’t can lead to confusing, unpredictable behavior.
Side-by-side examples engineers can pattern-match during review.
def foo(a): # Noncompliant, function will return "true" or None
if a == 1:
return True
returndef foo(a):
if a == 1:
return True
return FalseFrom the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.