decided-condition
A test the tests before it already decide.
- Group
- Code
- Runs
- On by default
- Level
- warning
- Reads
- Every file
- Fix
- None: removing a test changes which branches the code keeps, which is for its author to choose
Why
On every path to this test, the tests the code ran before it leave it one answer: it always holds, as n > 3 does after n > 5, or never holds, as n < 3 does there. The branch it guards is then always or never taken. Remove the test, or fix the test before it that was meant. The rule asks an SMT solver, and runs only where --solver names one.
The fix, as Ur suggests it: remove the test, or fix the test before it that was meant.
For agents
Write no test that the tests before it on every path already decide, such as n > 3 inside if n > 5.
Example
app/shipping.pydef shipping(weight):
if weight > 20:
if weight > 10:
return 15
return 25
return 5
$ ur lint --rule decided-condition --solver z3
warning[decided-condition]: `weight > 10` always holds here, after `weight > 20`
--> ./app/shipping.py:3:12 test
--> ./app/shipping.py:2:8 decided by
= hint: remove the test, or fix the test before it that was meant
0 clone classes and 1 `decided-condition` finding in 1 file