Skip to content

Commit 3cd9312

Browse files
author
Esben Sparre Andreasen
committed
JS: classify HTML files with > 20 elements on a line as generated
1 parent 4ab3407 commit 3cd9312

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

javascript/ql/src/semmle/javascript/GeneratedCode.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ private predicate isGeneratedHtml(File f) {
121121
e.getName() = "meta" and
122122
e.getAttributeByName("name").getValue() = "generator"
123123
)
124+
or
125+
20 < countStartingHtmlElements(f, _)
126+
}
127+
128+
/**
129+
* Gets an element that starts at line `l` in file `f`.
130+
*/
131+
private HTML::Element getAStartingElement(File f, int l) {
132+
result.getFile() = f and result.getLocation().getStartLine() = l
133+
}
134+
135+
136+
/**
137+
* Gets the number of HTML elements that starts at line `l` in file `f`.
138+
*/
139+
private int countStartingHtmlElements(File f, int l) {
140+
result = strictcount(getAStartingElement(f, l))
124141
}
125142

126143
/**

javascript/ql/test/query-tests/filters/ClassifyFiles/ClassifyFiles.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
| AutoRest.js:0:0:0:0 | AutoRest.js | generated |
2+
| ManyElementsOnLine.html:0:0:0:0 | ManyElementsOnLine.html | generated |
23
| ai.1.2.3-build0123.js:0:0:0:0 | ai.1.2.3-build0123.js | library |
34
| bundle-directive.js:0:0:0:0 | bundle-directive.js | generated |
45
| data.js:0:0:0:0 | data.js | generated |

0 commit comments

Comments
 (0)