@@ -6,20 +6,26 @@ import codeql.ruby.ApiGraphs
6
6
class ApiUseTest extends InlineExpectationsTest {
7
7
ApiUseTest ( ) { this = "ApiUseTest" }
8
8
9
- override string getARelevantTag ( ) { result = "use" }
9
+ override string getARelevantTag ( ) { result = [ "use" , "def" ] }
10
10
11
- private predicate relevantNode ( API:: Node a , DataFlow:: Node n , Location l ) {
12
- n = a .getAUse ( ) and
13
- l = n .getLocation ( )
11
+ private predicate relevantNode ( API:: Node a , DataFlow:: Node n , Location l , string tag ) {
12
+ l = n .getLocation ( ) and
13
+ (
14
+ tag = "use" and
15
+ n = a .getAUse ( )
16
+ or
17
+ tag = "def" and
18
+ n = a .getARhs ( )
19
+ )
14
20
}
15
21
16
22
override predicate hasActualResult ( Location location , string element , string tag , string value ) {
17
- exists ( API :: Node a , DataFlow :: Node n | relevantNode ( a , n , location ) |
18
- tag = "use" and
23
+ tag = "use" and // def tags are always optional
24
+ exists ( API :: Node a , DataFlow :: Node n | relevantNode ( a , n , location , tag ) |
19
25
// Only report the longest path on this line:
20
26
value =
21
27
max ( API:: Node a2 , Location l2 , DataFlow:: Node n2 |
22
- relevantNode ( a2 , n2 , l2 ) and
28
+ relevantNode ( a2 , n2 , l2 , tag ) and
23
29
l2 .getFile ( ) = location .getFile ( ) and
24
30
l2 .getStartLine ( ) = location .getStartLine ( )
25
31
|
@@ -34,8 +40,7 @@ class ApiUseTest extends InlineExpectationsTest {
34
40
// We also permit optional annotations for any other path on the line.
35
41
// This is used to test subclass paths, which typically have a shorter canonical path.
36
42
override predicate hasOptionalResult ( Location location , string element , string tag , string value ) {
37
- exists ( API:: Node a , DataFlow:: Node n | relevantNode ( a , n , location ) |
38
- tag = "use" and
43
+ exists ( API:: Node a , DataFlow:: Node n | relevantNode ( a , n , location , tag ) |
39
44
element = n .toString ( ) and
40
45
value = getAPath ( a , _)
41
46
)
0 commit comments