Skip to content

Commit 67745e6

Browse files
committed
Reused isGetPredicate to retrieve the prefix of the predicate
1 parent 7c1aa84 commit 67745e6

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

ql/ql/src/queries/style/ValidatePredicateGetReturns.ql

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import codeql_ql.ast.Ast
1616
* Identifies predicates whose names start with "get", "as" followed by an uppercase letter.
1717
* This ensures that only predicates like "getValue" are matched, excluding names like "getter".
1818
*/
19-
predicate isGetPredicate(Predicate pred) { pred.getName().regexpMatch("(get|as)[A-Z].*") }
19+
predicate isGetPredicate(Predicate pred, string prefix) {
20+
prefix = pred.getName().regexpCapture("(get|as)[A-Z].*", 1)
21+
}
2022

2123
/**
2224
* Checks if a predicate has a return type.
@@ -28,21 +30,9 @@ predicate hasReturnType(Predicate pred) { exists(pred.getReturnTypeExpr()) }
2830
*/
2931
predicate isAlias(Predicate pred) { exists(pred.(ClasslessPredicate).getAlias()) }
3032

31-
/**
32-
* Returns "get" if the predicate name starts with "get", otherwise "as".
33-
*/
34-
string getPrefix(Predicate pred) {
35-
if pred.getName().matches("get%")
36-
then result = "get"
37-
else
38-
if pred.getName().matches("as%")
39-
then result = "as"
40-
else result = ""
41-
}
42-
43-
from Predicate pred
33+
from Predicate pred, string prefix
4434
where
45-
isGetPredicate(pred) and
35+
isGetPredicate(pred, prefix) and
4636
not hasReturnType(pred) and
4737
not isAlias(pred)
48-
select pred, "This predicate starts with '" + getPrefix(pred) + "' but does not return a value."
38+
select pred, "This predicate starts with '" + prefix + "' but does not return a value."

0 commit comments

Comments
 (0)