trivial-expression
An expression always gives the same answer, or hands back one of its inputs.
- Group
- Code
- Runs
- On by default
- Level
- warning
- Reads
- Every file
- Fix
--fixfixes it: replaces the expression with its answer where the parts it drops run no effects
Why
Part of this expression does nothing: whatever its inputs, the expression evaluates to a constant or to one of its own parts, as x * 1 is x and x - x is 0. Replace it with its answer, or fix the operand that was meant. Each finding lists the language assumptions the simplification relied on.
The fix, as Ur suggests it: replace it with its answer, or fix the operand that was meant.
For agents
Write no operation or conditional whose result is a constant or one of its own operands, such as x * 1 or a if c else a.
Example
app/orders.pydef line_total(price: int, quantity: int) -> int:
return price * 1 * quantity
$ ur lint --rule trivial-expression
warning[trivial-expression]: `price * 1` is always `price`
--> ./app/orders.py:2:12 expression in `line_total`
= assumes: trusted-annotations
= hint: replace it with its answer, or fix the operand that was meant; `--fix` does this
0 clone classes and 1 trivial expression in 1 file