mirror of
https://github.com/github/codeql.git
synced 2026-05-03 04:39:29 +02:00
Python: Detect a wider range of generated files.
This commit is contained in:
@@ -24,6 +24,8 @@ library class GenericGeneratedFile extends GeneratedFile {
|
||||
(lax_generated_by(this, _) or lax_generated_from(this, _)) and dont_modify(this)
|
||||
or
|
||||
strict_generated_by(this, _) or strict_generated_from(this, _)
|
||||
or
|
||||
auto_generated(this)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -78,8 +80,15 @@ private predicate dont_modify(File f) {
|
||||
comment_or_docstring(f, _).regexpMatch("(?is).*\\b(Do not|Don't) (edit|modify|make changes)\\b.*")
|
||||
}
|
||||
|
||||
private predicate auto_generated(File f) {
|
||||
exists(Comment c |
|
||||
c.getLocation().getFile() = f and
|
||||
c.getText().regexpMatch("(?is)# *this +(code|file) +is +(auto(matically)?[ -]?generated|created automatically).*")
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* A file generated by a template engine
|
||||
*/
|
||||
abstract library class SpecificGeneratedFile extends GeneratedFile {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
| antlr.py | none |
|
||||
| generic.py | tools/idna-data |
|
||||
| sphinx.py | Sphinx |
|
||||
| swig.py | SWIG |
|
||||
|
||||
@@ -2,5 +2,9 @@
|
||||
import python
|
||||
import semmle.python.filters.GeneratedCode
|
||||
|
||||
from GeneratedFile f
|
||||
select f.toString(), f.getTool()
|
||||
from GeneratedFile f, string tool
|
||||
where
|
||||
tool = f.getTool()
|
||||
or
|
||||
not exists(f.getTool()) and tool = "none"
|
||||
select f.toString(), tool
|
||||
|
||||
11
python/ql/test/library-tests/filters/generated/antlr.py
Normal file
11
python/ql/test/library-tests/filters/generated/antlr.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# $ANTLR 3.0.1 C.g 2010-02-23 09:58:53
|
||||
|
||||
from antlr3 import *
|
||||
from antlr3.compat import set, frozenset
|
||||
|
||||
## @file
|
||||
# The file defines the parser for C source files.
|
||||
#
|
||||
# THIS FILE IS AUTO-GENERATED.
|
||||
#
|
||||
##
|
||||
Reference in New Issue
Block a user