Skip to content

Commit 5d625d6

Browse files
authored
Merge pull request #9188 from MathiasVP/fix-GetAPrimaryQlClassConsistency-for-swift
2 parents 6c7c9b6 + a6ac14f commit 5d625d6

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

ql/ql/src/queries/style/GetAPrimaryQlClassConsistency.ql

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,31 @@
1010

1111
import ql
1212

13-
from ClassPredicate pred, String constant
13+
/**
14+
* Gets a string that is allowed to be returned from the `getAPrimaryQlClass` implementation
15+
* in class `c`.
16+
*
17+
* For most languages this is just the name of `c`, but QL for Swift implements
18+
* the `getAPrimaryQlClass` predicate for a class `Foo` in another class `FooBase`.
19+
*/
20+
string getAnAllowedResultForClass(Class c) {
21+
result = c.getName()
22+
or
23+
c.getName() = result + "Base"
24+
}
25+
26+
from ClassPredicate pred, String constant, Class c
1427
where
15-
exists(string className, string constantName |
16-
pred.getParent().getName() = className and
17-
pred.getName() = "getAPrimaryQlClass" and
28+
c = pred.getParent() and
29+
pred.getName() = "getAPrimaryQlClass" and
30+
exists(string constantName |
1831
constant = pred.getBody().(ComparisonFormula).getRightOperand() and
1932
constant.getValue() = constantName and
2033
// might be "Foo::classname", detect by matching with a regexp
21-
not constantName.regexpMatch(".*\\b" + className + "$") and
34+
not constantName.regexpMatch(".*\\b" + getAnAllowedResultForClass(c) + "$") and
2235
// ignore constants with "?" in them
2336
not constantName.regexpMatch(".*\\?.*")
2437
)
2538
select pred,
26-
"The getAPrimaryQlClass predicate $@ instead of the class name \"" + pred.getParent().getName() +
27-
"\".", constant, "results in \"" + constant.getValue() + "\""
39+
"The getAPrimaryQlClass predicate $@ instead of the class name \"" + c.getName() + "\".",
40+
constant, "results in \"" + constant.getValue() + "\""

0 commit comments

Comments
 (0)