mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
JavaScript: Don't extract files with TypeScript progenitors
This commit is contained in:
@@ -818,9 +818,19 @@ public class AutoBuild {
|
||||
*/
|
||||
private boolean isFileDerivedFromTypeScriptFile(Path path, Set<Path> extractedFiles) {
|
||||
String name = path.getFileName().toString();
|
||||
if (!name.endsWith(".js"))
|
||||
// only skip JS variants when a corresponding TS/TSX file was already extracted
|
||||
if (!(name.endsWith(".js")
|
||||
|| name.endsWith(".cjs")
|
||||
|| name.endsWith(".mjs")
|
||||
|| name.endsWith(".jsx")
|
||||
|| name.endsWith(".cjsx")
|
||||
|| name.endsWith(".mjsx"))) {
|
||||
return false;
|
||||
String stem = name.substring(0, name.length() - ".js".length());
|
||||
}
|
||||
// strip off extension
|
||||
int dot = name.lastIndexOf('.');
|
||||
String stem = dot != -1 ? name.substring(0, dot) : name;
|
||||
// if a TS/TSX file with same base name was extracted, skip this file
|
||||
for (String ext : FileType.TYPESCRIPT.getExtensions()) {
|
||||
if (extractedFiles.contains(path.getParent().resolve(stem + ext))) {
|
||||
return true;
|
||||
|
||||
@@ -203,6 +203,25 @@ public class AutoBuildTests {
|
||||
runTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skipJsFilesDerivedFromTypeScriptFiles() throws IOException {
|
||||
// JS-derived files (.js, .cjs, .mjs, .jsx, .cjsx, .mjsx) should be skipped when TS indexing
|
||||
envVars.put("LGTM_INDEX_TYPESCRIPT", "basic");
|
||||
// Add TypeScript sources
|
||||
addFile(true, LGTM_SRC, "foo.ts");
|
||||
addFile(true, LGTM_SRC, "bar.tsx");
|
||||
// Add derived JS variants (should be skipped)
|
||||
addFile(false, LGTM_SRC, "foo.js");
|
||||
addFile(false, LGTM_SRC, "bar.jsx");
|
||||
addFile(false, LGTM_SRC, "foo.cjs");
|
||||
addFile(false, LGTM_SRC, "foo.mjs");
|
||||
addFile(false, LGTM_SRC, "bar.cjsx");
|
||||
addFile(false, LGTM_SRC, "bar.mjsx");
|
||||
// A normal JS file without TS counterpart should be extracted
|
||||
addFile(true, LGTM_SRC, "normal.js");
|
||||
runTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skipFilesInTsconfigOutDir() throws IOException {
|
||||
envVars.put("LGTM_INDEX_TYPESCRIPT", "basic");
|
||||
|
||||
Reference in New Issue
Block a user