Skip to content

Commit 746b13a

Browse files
authored
Merge pull request #510 from xiemaisi/js/exclude-minified
Approved by asger-semmle
2 parents a4bd586 + 19aa121 commit 746b13a

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

change-notes/1.19/extractor-javascript.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@
1616
1717
## General improvements
1818

19-
> Changes that affect alerts in many files or from many queries
20-
> For example, changes to file classification
19+
* On LGTM, files whose name ends in `.min.js` or `-min.js` are no longer extracted by default, since they most likely contain minified code and results in these files would be hidden by default anyway. To extract such files anyway, you can add the following filters to your `lgtm.yml` file (or add them to existing filters):
20+
21+
```yaml
22+
extraction:
23+
javascript:
24+
index:
25+
filters:
26+
- include: "**/*.min.js"
27+
- include: "**/*-min.js"
28+
```
2129
2230
## Changes to code extraction
2331

javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
*
112112
* <p>
113113
* The filtering phase is parameterised by a list of include/exclude patterns in the style of
114-
* {@link ProjectLayout} specifications. There are some built-in include patterns discussed
114+
* {@link ProjectLayout} specifications. There are some built-in include/exclude patterns discussed
115115
* below. Additionally, the environment variable <code>LGTM_INDEX_FILTERS</code> is interpreted
116116
* as a newline-separated list of patterns to append to that list (hence taking precedence over
117117
* the built-in patterns). Unlike for {@link ProjectLayout}, patterns in
@@ -140,6 +140,15 @@
140140
* </p>
141141
*
142142
* <p>
143+
* The default exclusion patterns cause the following files to be excluded:
144+
* </p>
145+
* <ul>
146+
* <li>All JavaScript files whose name ends with <code>-min.js</code> or <code>.min.js</code>.
147+
* Such files typically contain minified code. Since LGTM by default does not show results
148+
* in minified files, it is not usually worth extracting them in the first place.</li>
149+
* </ul>
150+
*
151+
* <p>
143152
* JavaScript files are normally extracted with {@link SourceType#AUTO}, but an explicit
144153
* source type can be specified in the environment variable <code>LGTM_INDEX_SOURCE_TYPE</code>.
145154
* </p>
@@ -317,6 +326,10 @@ private void setupFilters() {
317326
patterns.add("**/.eslintrc*");
318327
patterns.add("**/package.json");
319328

329+
// exclude files whose name strongly suggests they are minified
330+
patterns.add("-**/*.min.js");
331+
patterns.add("-**/*-min.js");
332+
320333
String base = LGTM_SRC.toString().replace('\\', '/');
321334
// process `$LGTM_INDEX_FILTERS`
322335
for (String pattern : Main.NEWLINE.split(getEnvVar("LGTM_INDEX_FILTERS", ""))) {

javascript/extractor/src/com/semmle/js/extractor/test/AutoBuildTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,4 +433,23 @@ public void excludeNonExistentFile() throws IOException {
433433
addFile(true, LGTM_SRC, "tst.js");
434434
runTest();
435435
}
436+
437+
@Test
438+
public void minifiedFilesAreExcluded() throws IOException {
439+
addFile(true, LGTM_SRC, "admin.js");
440+
addFile(false, LGTM_SRC, "jquery.min.js");
441+
addFile(false, LGTM_SRC, "lib", "lodash-min.js");
442+
addFile(true, LGTM_SRC, "compute_min.js");
443+
runTest();
444+
}
445+
446+
@Test
447+
public void minifiedFilesCanBeReIncluded() throws IOException {
448+
envVars.put("LGTM_INDEX_FILTERS", "include:**/*.min.js\ninclude:**/*-min.js");
449+
addFile(true, LGTM_SRC, "admin.js");
450+
addFile(true, LGTM_SRC, "jquery.min.js");
451+
addFile(true, LGTM_SRC, "lib", "lodash-min.js");
452+
addFile(true, LGTM_SRC, "compute_min.js");
453+
runTest();
454+
}
436455
}

0 commit comments

Comments
 (0)