JS: classify single-line JSON files as generated

This commit is contained in:
Esben Sparre Andreasen
2019-06-12 09:00:59 +02:00
parent 7790ac45bd
commit 29f9103b39
3 changed files with 18 additions and 1 deletions

View File

@@ -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())
}

View File

@@ -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 |

View File

@@ -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"]}]