Skip to content

Commit 7149b98

Browse files
committed
add ql/counting-to-zero
1 parent 1d10f14 commit 7149b98

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @name Counting zero elements
3+
* @description Use not exists instead of checking that there is zero elements in a set.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @id ql/counting-to-zero
7+
* @precision high
8+
*/
9+
10+
import ql
11+
12+
from ComparisonFormula comp, int c, string msg
13+
where
14+
c = 0 and // [0, 1] and // skipping the 1 case for now, as it seems too noisy.
15+
comp.getOperator() = ["=", "!="] and
16+
comp.getAnOperand().(Integer).getValue() = c and
17+
comp.getAnOperand().(Aggregate).getKind() = ["count", "strictcount"] and
18+
if c = 0
19+
then msg = "Use not exists(..) instead of checking that there is zero elements in a set."
20+
else msg = "Use unique(.. | |) instead of checking that there is one element in a set."
21+
select comp, msg

0 commit comments

Comments
 (0)