mirror of
https://github.com/github/codeql.git
synced 2025-12-17 17:23:36 +01:00
36 lines
1.1 KiB
Plaintext
36 lines
1.1 KiB
Plaintext
import python
|
|
import semmle.python.dataflow.new.DataFlow
|
|
import TestUtilities.InlineExpectationsTest
|
|
import semmle.python.ApiGraphs
|
|
|
|
class ApiUseTest extends InlineExpectationsTest {
|
|
ApiUseTest() { this = "ApiUseTest" }
|
|
|
|
override string getARelevantTag() { result = "use" }
|
|
|
|
private predicate relevant_node(API::Node a, DataFlow::Node n, Location l) {
|
|
n = a.getAUse() and
|
|
l = n.getLocation() and
|
|
// Module variable nodes have no suitable location, so it's best to simply exclude them entirely
|
|
// from the inline tests.
|
|
not n instanceof DataFlow::ModuleVariableNode and
|
|
exists(l.getFile().getRelativePath())
|
|
}
|
|
|
|
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
|
exists(API::Node a, DataFlow::Node n | relevant_node(a, n, location) |
|
|
tag = "use" and
|
|
// Only report the longest path on this line:
|
|
value =
|
|
max(API::Node a2, Location l2 |
|
|
relevant_node(a2, _, l2) and
|
|
l2.getFile() = location.getFile() and
|
|
l2.getStartLine() = location.getStartLine()
|
|
|
|
|
a2.getPath()
|
|
) and
|
|
element = n.toString()
|
|
)
|
|
}
|
|
}
|