From a462ec91f5d6e8e881f370a6823202f8c6f1c400 Mon Sep 17 00:00:00 2001 From: Napalys Date: Fri, 29 Nov 2024 15:54:58 +0100 Subject: [PATCH] Now the error message reflects properly the prefix --- .../queries/style/ValidatePredicateGetReturns.ql | 14 +++++++++++++- .../ValidatePredicateGetReturns.expected | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ql/ql/src/queries/style/ValidatePredicateGetReturns.ql b/ql/ql/src/queries/style/ValidatePredicateGetReturns.ql index 065e24f9b2e4..ad7db6e05907 100644 --- a/ql/ql/src/queries/style/ValidatePredicateGetReturns.ql +++ b/ql/ql/src/queries/style/ValidatePredicateGetReturns.ql @@ -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." diff --git a/ql/ql/test/queries/style/ValidatePredicateGetReturns/ValidatePredicateGetReturns.expected b/ql/ql/test/queries/style/ValidatePredicateGetReturns/ValidatePredicateGetReturns.expected index a79e572ed1cd..57469246ae82 100644 --- a/ql/ql/test/queries/style/ValidatePredicateGetReturns/ValidatePredicateGetReturns.expected +++ b/ql/ql/test/queries/style/ValidatePredicateGetReturns/ValidatePredicateGetReturns.expected @@ -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. |