Skip to content

Commit fb5513c

Browse files
authored
QL: Add "implicit this" query
1 parent d1721d0 commit fb5513c

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @name Using implicit `this`
3+
* @description Writing member predicate calls with an implicit `this` can be confusing
4+
* @kind problem
5+
* @problem.severity warning
6+
* @precision very-high
7+
* @id ql/implicit-this
8+
* @tags maintainability
9+
*/
10+
11+
import ql
12+
13+
MemberCall explicitThisCallInFile(File f) {
14+
result.getLocation().getFile() = f and
15+
result.getBase() instanceof ThisAccess and
16+
// Exclude `this.(Type).whatever(...)`, as some files have that as their only instance of `this`.
17+
not result = any(InlineCast c).getBase()
18+
}
19+
20+
PredicateCall implicitThisCallInFile(File f) {
21+
result.getLocation().getFile() = f and
22+
exists(result.getTarget().getDeclaringType().getASuperType()) and
23+
// Exclude `SomeModule::whatever(...)`
24+
not exists(result.getQualifier())
25+
}
26+
27+
PredicateCall confusingImplicitThisCall(File f) {
28+
result = implicitThisCallInFile(f) and
29+
exists(explicitThisCallInFile(f))
30+
}
31+
32+
from PredicateCall c
33+
where c = confusingImplicitThisCall(_)
34+
select c, "Use of implicit `this`."

0 commit comments

Comments
 (0)