mirror of
https://github.com/github/codeql.git
synced 2026-01-29 06:12:58 +01:00
Add GeneratedFile concept
This commit is contained in:
@@ -8,17 +8,6 @@
|
||||
|
||||
import go
|
||||
|
||||
string generatorCommentRegex() {
|
||||
result = "Generated By\\b.*\\bDo not edit" or
|
||||
result = "This (file|class|interface|art[ei]fact) (was|is|(has been)) (?:auto[ -]?)?gener(e?)ated" or
|
||||
result = "Any modifications to this file will be lost" or
|
||||
result =
|
||||
"This (file|class|interface|art[ei]fact) (was|is) (?:mechanically|automatically) generated" or
|
||||
result = "The following code was (?:auto[ -]?)?generated (?:by|from)" or
|
||||
result = "Autogenerated by Thrift" or
|
||||
result = "(Code g|G)enerated from .* by ANTLR"
|
||||
}
|
||||
|
||||
predicate classify(File f, string category) {
|
||||
// tests
|
||||
f instanceof TestFile and
|
||||
@@ -29,13 +18,7 @@ predicate classify(File f, string category) {
|
||||
category = "library"
|
||||
or
|
||||
// generated code
|
||||
exists(Comment c | c.getFile() = f |
|
||||
c.getText().regexpMatch("(?i).*\\b(" + concat(generatorCommentRegex(), "|") + ")\\b.*")
|
||||
or
|
||||
// regular expression recommended for Go code generators
|
||||
// (https://golang.org/pkg/cmd/go/internal/generate/)
|
||||
c.getText().regexpMatch("^\\s*Code generated .* DO NOT EDIT\\.\\s*$")
|
||||
) and
|
||||
f instanceof GeneratedFile and
|
||||
category = "generated"
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
import go
|
||||
import semmle.go.dataflow.FunctionInputsAndOutputs
|
||||
|
||||
import semmle.go.concepts.HTTP
|
||||
import semmle.go.concepts.GeneratedFile
|
||||
|
||||
/**
|
||||
* A data-flow node that executes an operating system command,
|
||||
|
||||
50
ql/src/semmle/go/concepts/GeneratedFile.qll
Normal file
50
ql/src/semmle/go/concepts/GeneratedFile.qll
Normal file
@@ -0,0 +1,50 @@
|
||||
/** Provides a class for generated files. */
|
||||
|
||||
import go
|
||||
|
||||
/** Provides a class for generated files. */
|
||||
module GeneratedFile {
|
||||
/**
|
||||
* A file that has been generated.
|
||||
*
|
||||
* Extend this class to model new APIs. If you want to refine existing API models,
|
||||
* extend `GeneratedFile` instead.
|
||||
*/
|
||||
abstract class Range extends File { }
|
||||
|
||||
private string generatorCommentRegex() {
|
||||
result = "Generated By\\b.*\\bDo not edit" or
|
||||
result =
|
||||
"This (file|class|interface|art[ei]fact) (was|is|(has been)) (?:auto[ -]?)?gener(e?)ated" or
|
||||
result = "Any modifications to this file will be lost" or
|
||||
result =
|
||||
"This (file|class|interface|art[ei]fact) (was|is) (?:mechanically|automatically) generated" or
|
||||
result = "The following code was (?:auto[ -]?)?generated (?:by|from)" or
|
||||
result = "Autogenerated by Thrift" or
|
||||
result = "(Code g|G)enerated from .* by ANTLR"
|
||||
}
|
||||
|
||||
private class CommentHeuristicGeneratedFile extends Range {
|
||||
CommentHeuristicGeneratedFile() {
|
||||
exists(Comment c | c.getFile() = this |
|
||||
c.getText().regexpMatch("(?i).*\\b(" + concat(generatorCommentRegex(), "|") + ")\\b.*")
|
||||
or
|
||||
// regular expression recommended for Go code generators
|
||||
// (https://golang.org/pkg/cmd/go/internal/generate/)
|
||||
c.getText().regexpMatch("^\\s*Code generated .* DO NOT EDIT\\.\\s*$")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A file that has been generated.
|
||||
*
|
||||
* Extend this class to refine existing API models. If you want to model new APIs,
|
||||
* extend `GeneratedFile::Range` instead.
|
||||
*/
|
||||
class GeneratedFile extends File {
|
||||
GeneratedFile::Range self;
|
||||
|
||||
GeneratedFile() { this = self }
|
||||
}
|
||||
Reference in New Issue
Block a user