mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
Ruby: Move TestFile to modeling Util module
The TestFile class in the ModelEditor module is more accurate than the existing RelevantFile class in the Util module, so this moves the TestFile class to Util and redefines RelevantFile in terms of the TestFile.
This commit is contained in:
@@ -5,13 +5,23 @@
|
||||
private import ruby
|
||||
private import codeql.ruby.ApiGraphs
|
||||
|
||||
/**
|
||||
* A file that probably contains tests.
|
||||
*/
|
||||
class TestFile extends File {
|
||||
TestFile() {
|
||||
this.getRelativePath().regexpMatch(".*(test|spec|examples).+") and
|
||||
not this.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A file that is relevant in the context of library modeling.
|
||||
*
|
||||
* In practice, this means a file that is not part of test code.
|
||||
*/
|
||||
class RelevantFile extends File {
|
||||
RelevantFile() { not this.getRelativePath().regexpMatch(".*/?test(case)?s?/.*") }
|
||||
RelevantFile() { not this instanceof TestFile }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,11 +9,6 @@ private import codeql.ruby.frameworks.data.ModelsAsData
|
||||
private import codeql.ruby.frameworks.data.internal.ApiGraphModelsExtensions
|
||||
private import queries.modeling.internal.Util as Util
|
||||
|
||||
/** Holds if the given callable is not worth supporting. */
|
||||
private predicate isUninteresting(DataFlow::MethodNode c) {
|
||||
c.getLocation().getFile() instanceof TestFile
|
||||
}
|
||||
|
||||
private predicate gemFileStep(Gem::GemSpec gem, Folder folder, int n) {
|
||||
n = 0 and folder.getAFile() = gem.(File)
|
||||
or
|
||||
@@ -63,7 +58,7 @@ abstract class Endpoint instanceof DataFlow::Node {
|
||||
class MethodEndpoint extends Endpoint instanceof DataFlow::MethodNode {
|
||||
MethodEndpoint() {
|
||||
this.isPublic() and
|
||||
not isUninteresting(this)
|
||||
this.(DataFlow::MethodNode).getLocation().getFile() instanceof Util::RelevantFile
|
||||
}
|
||||
|
||||
DataFlow::MethodNode getNode() { result = this }
|
||||
@@ -144,19 +139,12 @@ class MethodEndpoint extends Endpoint instanceof DataFlow::MethodNode {
|
||||
}
|
||||
|
||||
string methodClassification(Call method) {
|
||||
method.getFile() instanceof TestFile and result = "test"
|
||||
method.getFile() instanceof Util::TestFile and result = "test"
|
||||
or
|
||||
not method.getFile() instanceof TestFile and
|
||||
not method.getFile() instanceof Util::TestFile and
|
||||
result = "source"
|
||||
}
|
||||
|
||||
class TestFile extends File {
|
||||
TestFile() {
|
||||
this.getRelativePath().regexpMatch(".*(test|spec|examples).+") and
|
||||
not this.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A callable where there exists a MaD sink model that applies to it.
|
||||
*/
|
||||
@@ -222,7 +210,7 @@ class ModuleEndpoint extends Endpoint {
|
||||
n order by loc.getFile().getAbsolutePath(), loc.getStartLine(), loc.getStartColumn()
|
||||
) and
|
||||
not moduleNode.(Module).isBuiltin() and
|
||||
not moduleNode.getLocation().getFile() instanceof TestFile
|
||||
moduleNode.getLocation().getFile() instanceof Util::RelevantFile
|
||||
}
|
||||
|
||||
DataFlow::ModuleNode getNode() { result = moduleNode }
|
||||
|
||||
Reference in New Issue
Block a user