mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Merge pull request #657 from esben-semmle/js/classify-more-files
JS: classify additional files
This commit is contained in:
@@ -42,8 +42,8 @@ class CodeGeneratorMarkerComment extends GeneratedCodeMarkerComment {
|
||||
*/
|
||||
private predicate codeGeneratorMarkerComment(Comment c, string tool) {
|
||||
exists (string toolPattern |
|
||||
toolPattern = "js_of_ocaml|CoffeeScript|LiveScript|dart2js|ANTLR|PEG\\.js|Opal|JSX|jison(?:-lex)?" and
|
||||
tool = c.getText().regexpCapture("(?s)[\\s*]*(?:parser )?[gG]eneratedy? (?:from .*)?by (" + toolPattern + ")\\b.*", 1)
|
||||
toolPattern = "js_of_ocaml|CoffeeScript|LiveScript|dart2js|ANTLR|PEG\\.js|Opal|JSX|jison(?:-lex)?|(?:Microsoft \\(R\\) AutoRest Code Generator)|purs" and
|
||||
tool = c.getText().regexpCapture("(?s)[\\s*]*(?:parser |Code )?[gG]eneratedy? (?:from .*)?by (" + toolPattern + ")\\b.*", 1)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -114,6 +114,17 @@ private predicate isData(File f) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `f` is a generated HTML file.
|
||||
*/
|
||||
private predicate isGeneratedHtml(File f) {
|
||||
exists(HTML::Element e |
|
||||
e.getFile() = f and
|
||||
e.getName() = "meta" and
|
||||
e.getAttributeByName("name").getValue() = "generator"
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `tl` looks like it contains generated code.
|
||||
*/
|
||||
@@ -124,12 +135,14 @@ predicate isGenerated(TopLevel tl) {
|
||||
tl instanceof DartGeneratedTopLevel or
|
||||
exists (GeneratedCodeMarkerComment gcmc | tl = gcmc.getTopLevel()) or
|
||||
hasManyInvocations(tl) or
|
||||
isData(tl.getFile())
|
||||
isData(tl.getFile()) or
|
||||
isGeneratedHtml(tl.getFile())
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `file` look like it contains generated code.
|
||||
*/
|
||||
predicate isGeneratedCode(File file) {
|
||||
isGenerated(file.getATopLevel())
|
||||
isGenerated(file.getATopLevel()) or
|
||||
isGeneratedHtml(file)
|
||||
}
|
||||
|
||||
@@ -222,10 +222,10 @@ predicate isMultiLicenseBundle(TopLevel tl) {
|
||||
)
|
||||
) > 1
|
||||
or
|
||||
// case: ordinary block comments with "@license" lines
|
||||
// case: ordinary block comments lines that start with a license
|
||||
count(BlockComment head |
|
||||
head.getTopLevel() = tl and
|
||||
head.getLine(_).regexpMatch("(?i) *\\* @license .*")
|
||||
head.getLine(_).regexpMatch("(?i)[\\s*]*(@license\\b.*|The [a-z0-9-]+ License (\\([a-z0-9-]+\\))?\\s*)")
|
||||
) > 1
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user