File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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`."
You can’t perform that action at this time.
0 commit comments