File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments