mirror of
https://github.com/github/codeql.git
synced 2026-05-02 12:15:17 +02:00
JS: classify generated data files
This commit is contained in:
@@ -99,6 +99,21 @@ private predicate hasManyInvocations(TopLevel tl) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `f` is side effect free, and full of primitive literals, which is often a sign of generated data code.
|
||||
*/
|
||||
private predicate isData(File f) {
|
||||
// heuristic: `f` has more than 1000 primitive literal expressions ...
|
||||
count(SyntacticConstants::PrimitiveLiteralConstant e | e.getFile() = f) > 1000 and
|
||||
// ... but no expressions with side effects ...
|
||||
not exists (Expr e |
|
||||
e.getFile() = f and
|
||||
e.isImpure() and
|
||||
// ... except for variable initializers
|
||||
not e instanceof VariableDeclarator
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `tl` looks like it contains generated code.
|
||||
*/
|
||||
@@ -108,7 +123,8 @@ predicate isGenerated(TopLevel tl) {
|
||||
tl instanceof GWTGeneratedTopLevel or
|
||||
tl instanceof DartGeneratedTopLevel or
|
||||
exists (GeneratedCodeMarkerComment gcmc | tl = gcmc.getTopLevel()) or
|
||||
hasManyInvocations(tl)
|
||||
hasManyInvocations(tl) or
|
||||
isData(tl.getFile())
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
| ai.1.2.3-build0123.js:0:0:0:0 | ai.1.2.3-build0123.js | library |
|
||||
| bundle-directive.js:0:0:0:0 | bundle-directive.js | generated |
|
||||
| data.js:0:0:0:0 | data.js | generated |
|
||||
| exported-data.js:0:0:0:0 | exported-data.js | generated |
|
||||
| jison-lex.js:0:0:0:0 | jison-lex.js | generated |
|
||||
| jison.js:0:0:0:0 | jison.js | generated |
|
||||
| jquery-datatables.js:0:0:0:0 | jquery-datatables.js | library |
|
||||
|
||||
1202
javascript/ql/test/query-tests/filters/ClassifyFiles/data.js
Normal file
1202
javascript/ql/test/query-tests/filters/ClassifyFiles/data.js
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user