Skip to content

Commit 5ebcef4

Browse files
author
Esben Sparre Andreasen
committed
JS: classify numeric file names as generated
1 parent 927d724 commit 5ebcef4

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ private int countStartingHtmlElements(File f, int l) {
154154
result = strictcount(getAStartingElement(f, l))
155155
}
156156

157+
/**
158+
* Holds if the base name of `f` is a number followed by a single extension.
159+
*/
160+
predicate isGenerateFileName(File f) {
161+
f.getStem().regexpMatch("[0-9]+")
162+
}
163+
157164
/**
158165
* Holds if `tl` looks like it contains generated code.
159166
*/
@@ -166,7 +173,8 @@ predicate isGenerated(TopLevel tl) {
166173
hasManyInvocations(tl) or
167174
isData(tl.getFile()) or
168175
isJsonLine(tl.getFile()) or
169-
isGeneratedHtml(tl.getFile())
176+
isGeneratedHtml(tl.getFile()) or
177+
isGenerateFileName(tl.getFile())
170178
}
171179

172180
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var x = 42;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var x = 42;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| 1.js:0:0:0:0 | 1.js | generated |
12
| AutoRest.js:0:0:0:0 | AutoRest.js | generated |
23
| ManyElementsOnLine.html:0:0:0:0 | ManyElementsOnLine.html | generated |
34
| ai.1.2.3-build0123.js:0:0:0:0 | ai.1.2.3-build0123.js | library |

0 commit comments

Comments
 (0)