Skip to content

Commit 7837959

Browse files
committed
QL: Add query to find Android queries with improper ids
1 parent 579c56c commit 7837959

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @name Android query without android @id prefix
3+
* @description Android queries should include the `android` prefix in their `@id`.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @id ql/android-id-prefix
7+
* @precision high
8+
*/
9+
10+
import ql
11+
12+
string getIdProperty(QLDoc doc) {
13+
result = any(string id | id = doc.getContents().splitAt("@") and id.matches("id %"))
14+
}
15+
16+
predicate importsAndroidModule(TopLevel t) {
17+
exists(Import i | t.getAnImport() = i |
18+
i.getImportString().toLowerCase().matches("%android%")
19+
or
20+
exists(TopLevel t2 |
21+
t2.getAModule() = i.getResolvedModule().asModule() and
22+
importsAndroidModule(t2)
23+
)
24+
)
25+
}
26+
27+
from TopLevel t
28+
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`."

0 commit comments

Comments
 (0)