-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathComplexCondition.ql
More file actions
29 lines (25 loc) · 956 Bytes
/
ComplexCondition.ql
File metadata and controls
29 lines (25 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* @name Complex condition
* @description Boolean expressions should not be too deeply nested. Naming intermediate results as local variables will make the logic easier to read and understand.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id cs/complex-condition
* @tags testability
* readability
*/
import csharp
predicate nontrivialLogicalOperator(BinaryLogicalOperation e) {
not exists(BinaryLogicalOperation parent |
parent = e.getParent() and
parent.getOperator() = e.getOperator()
)
}
predicate logicalParent(LogicalOperation op, LogicalOperation parent) { parent = op.getParent() }
from Expr e, int operators
where
not e.getParent() instanceof LogicalOperation and
operators =
count(BinaryLogicalOperation op | logicalParent*(op, e) and nontrivialLogicalOperator(op)) and
operators > 3
select e.getLocation(), "Complex condition: too many logical operations in this expression."