Skip to content

Commit

Permalink
Now the error message reflects properly the prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Napalys committed Nov 29, 2024
1 parent 96c1086 commit a462ec9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion ql/ql/src/queries/style/ValidatePredicateGetReturns.ql
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,21 @@ predicate hasReturnType(Predicate pred) { exists(pred.getReturnType()) }
*/
predicate isAlias(Predicate pred) { exists(pred.(ClasslessPredicate).getAlias()) }

/**
* Returns "get" if the predicate name starts with "get", otherwise "as".
*/
string getPrefix(Predicate pred) {
if pred.getName().matches("get%")
then result = "get"
else
if pred.getName().matches("as%")
then result = "as"
else result = ""
}

from Predicate pred
where
isGetPredicate(pred) and
not hasReturnType(pred) and
not isAlias(pred)
select pred, "This predicate starts with 'get' but does not return a value."
select pred, "This predicate starts with '" + getPrefix(pred) + "' but does not return a value."
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
| test.qll:4:11:4:18 | ClasslessPredicate getValue | This predicate starts with 'get' but does not return a value. |
| test.qll:25:11:25:28 | ClasslessPredicate getImplementation2 | This predicate starts with 'get' but does not return a value. |
| test.qll:31:11:31:17 | ClasslessPredicate asValue | This predicate starts with 'get' but does not return a value. |
| test.qll:31:11:31:17 | ClasslessPredicate asValue | This predicate starts with 'as' but does not return a value. |

0 comments on commit a462ec9

Please sign in to comment.