mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
JS: classify single-line JSON files as generated
This commit is contained in:
@@ -112,6 +112,21 @@ private predicate isData(File f) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `f` is a single line that looks like a non-trivial amount of JSON data, which is often a sign of generated data code.
|
||||
*/
|
||||
private predicate isJsonLine(File f) {
|
||||
f.getNumberOfLines() = 1 and
|
||||
count(Expr e | e.getFile() = f) > 100 and
|
||||
forall(Expr e | e.getFile() = f |
|
||||
e instanceof ObjectExpr or
|
||||
e instanceof ArrayExpr or
|
||||
e instanceof NumberLiteral or
|
||||
e instanceof StringLiteral or
|
||||
e instanceof BooleanLiteral
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `f` is a generated HTML file.
|
||||
*/
|
||||
@@ -132,7 +147,6 @@ private HTML::Element getAStartingElement(File f, int l) {
|
||||
result.getFile() = f and result.getLocation().getStartLine() = l
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number of HTML elements that start at line `l` in file `f`.
|
||||
*/
|
||||
@@ -151,6 +165,7 @@ predicate isGenerated(TopLevel tl) {
|
||||
exists(GeneratedCodeMarkerComment gcmc | tl = gcmc.getTopLevel()) or
|
||||
hasManyInvocations(tl) or
|
||||
isData(tl.getFile()) or
|
||||
isJsonLine(tl.getFile()) or
|
||||
isGeneratedHtml(tl.getFile())
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
| jquery-datatables.js:0:0:0:0 | jquery-datatables.js | library |
|
||||
| jquery-jstree.js:0:0:0:0 | jquery-jstree.js | library |
|
||||
| jquery-snippet.js:0:0:0:0 | jquery-snippet.js | library |
|
||||
| json-like.js:0:0:0:0 | json-like.js | generated |
|
||||
| jsx-old.js:0:0:0:0 | jsx-old.js | generated |
|
||||
| jsx.js:0:0:0:0 | jsx.js | generated |
|
||||
| multi-part-bundle.html:0:0:0:0 | multi-part-bundle.html | generated |
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[{"x":"x"},{"x":"x","x":{"x":{"x":"x","x":"x","x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x","x":"x"},"x":{"x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x","x":"x"}},"x":"x","x":["x","x"]},{"x":"x","x":{"x":{"x":"x","x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x"},"x":{"x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x"},"x":{"x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x"},"x":{"x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x","x":"x"}},"x":"x","x":["x","x"]},{"x":"x","x":{"x":{"x":"x","x":"x","x":"x"}},"x":"x","x":["x","x"]},{"x":"x","x":{"x":{"x":"x","x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x","x":"x","x":"x"}},"x":"x","x":["x","x"]},{"x":"x","x":{"x":{"x":"x","x":"x","x":"x"}},"x":"x","x":["x","x"]},{"x":"x","x":{"x":{"x":"x","x":"x"}},"x":"x","x":["x"]},{"x":"x","x":{"x":{"x":"x"}},"x":"x","x":["x"]}]
|
||||
Reference in New Issue
Block a user