Skip to content

Commit 4153480

Browse files
committed
Refactor to use QueryDoc
Kudos to @erik-krogh for the suggestion.
1 parent 7837959 commit 4153480

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name Android query without android @id prefix
3-
* @description Android queries should include the `android` prefix in their `@id`.
3+
* @description Android queries should include the `android/` prefix in their `@id`.
44
* @kind problem
55
* @problem.severity warning
66
* @id ql/android-id-prefix
@@ -9,10 +9,7 @@
99

1010
import ql
1111

12-
string getIdProperty(QLDoc doc) {
13-
result = any(string id | id = doc.getContents().splitAt("@") and id.matches("id %"))
14-
}
15-
12+
/** Holds if `t` transitively imports an Android module. */
1613
predicate importsAndroidModule(TopLevel t) {
1714
exists(Import i | t.getAnImport() = i |
1815
i.getImportString().toLowerCase().matches("%android%")
@@ -24,9 +21,9 @@ predicate importsAndroidModule(TopLevel t) {
2421
)
2522
}
2623

27-
from TopLevel t
24+
from QueryDoc d
2825
where
29-
t.getLocation().getFile().getRelativePath().matches("%src/Security/%.ql") and
30-
not getIdProperty(t.getQLDoc()).matches("% java/android/%") and
31-
importsAndroidModule(t)
32-
select t, "This Android query is missing the `android` prefix in its `@id`."
26+
d.getLocation().getFile().getRelativePath().matches("%src/Security/%") and
27+
not d.getQueryId().matches("android/%") and
28+
importsAndroidModule(d.getParent())
29+
select d, "This Android query is missing the `android/` prefix in its `@id`."

0 commit comments

Comments
 (0)