Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
ql/counting-to-zero
1 parent 1d10f14 commit 7149b98Copy full SHA for 7149b98
1 file changed
ql/ql/src/queries/style/CountingToZero.ql
@@ -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