mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
JS: Remove TypeScriptMode
This commit is contained in:
@@ -218,7 +218,6 @@ public class AutoBuild {
|
||||
private final Set<String> xmlExtensions = new LinkedHashSet<>();
|
||||
private ProjectLayout filters;
|
||||
private final Path LGTM_SRC, SEMMLE_DIST;
|
||||
private final TypeScriptMode typeScriptMode;
|
||||
private final String defaultEncoding;
|
||||
private ExecutorService threadPool;
|
||||
private volatile boolean seenCode = false;
|
||||
@@ -236,8 +235,6 @@ public class AutoBuild {
|
||||
this.SEMMLE_DIST = Paths.get(EnvironmentVariables.getExtractorRoot());
|
||||
this.outputConfig = new ExtractorOutputConfig(LegacyLanguage.JAVASCRIPT);
|
||||
this.trapCache = ITrapCache.fromExtractorOptions();
|
||||
this.typeScriptMode =
|
||||
getEnumFromEnvVar("LGTM_INDEX_TYPESCRIPT", TypeScriptMode.class, TypeScriptMode.BASIC);
|
||||
this.defaultEncoding = getEnvVar("LGTM_INDEX_DEFAULT_ENCODING");
|
||||
this.installDependencies = Boolean.valueOf(getEnvVar("LGTM_INDEX_TYPESCRIPT_INSTALL_DEPS"));
|
||||
this.virtualSourceRoot = makeVirtualSourceRoot();
|
||||
@@ -393,7 +390,7 @@ public class AutoBuild {
|
||||
defaultExtract.add(FileType.HTML);
|
||||
defaultExtract.add(FileType.JS);
|
||||
defaultExtract.add(FileType.YAML);
|
||||
if (typeScriptMode != TypeScriptMode.NONE) defaultExtract.add(FileType.TYPESCRIPT);
|
||||
defaultExtract.add(FileType.TYPESCRIPT);
|
||||
for (FileType filetype : defaultExtract)
|
||||
for (String extension : filetype.getExtensions()) patterns.add("**/*" + extension);
|
||||
|
||||
@@ -1042,7 +1039,6 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path>
|
||||
private ExtractorConfig mkExtractorConfig() {
|
||||
ExtractorConfig config = new ExtractorConfig(true);
|
||||
config = config.withSourceType(getSourceType());
|
||||
config = config.withTypeScriptMode(typeScriptMode);
|
||||
config = config.withVirtualSourceRoot(virtualSourceRoot);
|
||||
if (defaultEncoding != null) config = config.withDefaultEncoding(defaultEncoding);
|
||||
return config;
|
||||
@@ -1135,8 +1131,7 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path>
|
||||
}
|
||||
|
||||
// extract TypeScript projects from 'tsconfig.json'
|
||||
if (typeScriptMode != TypeScriptMode.NONE
|
||||
&& treatAsTSConfig(file.getFileName().toString())
|
||||
if (treatAsTSConfig(file.getFileName().toString())
|
||||
&& !excludes.contains(file)
|
||||
&& isFileIncluded(file)) {
|
||||
tsconfigFiles.add(file);
|
||||
|
||||
@@ -221,9 +221,6 @@ public class ExtractorConfig {
|
||||
/** Should textual information be extracted into the lines/4 relation? */
|
||||
private boolean extractLines;
|
||||
|
||||
/** Should TypeScript files be extracted? */
|
||||
private TypeScriptMode typescriptMode;
|
||||
|
||||
/** Override amount of RAM to allocate to the TypeScript compiler. */
|
||||
private int typescriptRam;
|
||||
|
||||
@@ -245,7 +242,6 @@ public class ExtractorConfig {
|
||||
this.esnext = true;
|
||||
this.v8Extensions = true;
|
||||
}
|
||||
this.typescriptMode = TypeScriptMode.NONE;
|
||||
this.e4x = experimental;
|
||||
this.defaultEncoding = StandardCharsets.UTF_8.name();
|
||||
this.virtualSourceRoot = VirtualSourceRoot.none;
|
||||
@@ -266,7 +262,6 @@ public class ExtractorConfig {
|
||||
this.sourceType = that.sourceType;
|
||||
this.htmlHandling = that.htmlHandling;
|
||||
this.extractLines = that.extractLines;
|
||||
this.typescriptMode = that.typescriptMode;
|
||||
this.typescriptRam = that.typescriptRam;
|
||||
this.defaultEncoding = that.defaultEncoding;
|
||||
this.virtualSourceRoot = that.virtualSourceRoot;
|
||||
@@ -416,20 +411,10 @@ public class ExtractorConfig {
|
||||
return res;
|
||||
}
|
||||
|
||||
public TypeScriptMode getTypeScriptMode() {
|
||||
return typescriptMode;
|
||||
}
|
||||
|
||||
public int getTypeScriptRam() {
|
||||
return typescriptRam;
|
||||
}
|
||||
|
||||
public ExtractorConfig withTypeScriptMode(TypeScriptMode typescriptMode) {
|
||||
ExtractorConfig res = new ExtractorConfig(this);
|
||||
res.typescriptMode = typescriptMode;
|
||||
return res;
|
||||
}
|
||||
|
||||
public ExtractorConfig withTypeScriptRam(int ram) {
|
||||
ExtractorConfig res = new ExtractorConfig(this);
|
||||
res.typescriptRam = ram;
|
||||
@@ -490,8 +475,6 @@ public class ExtractorConfig {
|
||||
+ sourceType
|
||||
+ ", extractLines="
|
||||
+ extractLines
|
||||
+ ", typescriptMode="
|
||||
+ typescriptMode
|
||||
+ ", defaultEncoding="
|
||||
+ defaultEncoding
|
||||
+ ", virtualSourceRoot="
|
||||
|
||||
@@ -217,8 +217,6 @@ public class FileExtractor {
|
||||
TYPESCRIPT(".ts", ".tsx", ".mts", ".cts") {
|
||||
@Override
|
||||
protected boolean contains(File f, String lcExt, ExtractorConfig config) {
|
||||
if (config.getTypeScriptMode() == TypeScriptMode.NONE) return false;
|
||||
|
||||
// Read the beginning of the file to guess the file type.
|
||||
if (hasBadFileHeader(f, lcExt, config)) {
|
||||
return false;
|
||||
|
||||
@@ -77,7 +77,6 @@ public class Main {
|
||||
private PathMatcher includeMatcher, excludeMatcher;
|
||||
private FileExtractor fileExtractor;
|
||||
private ExtractorState extractorState;
|
||||
private Set<File> projectFiles = new LinkedHashSet<>();
|
||||
private Set<File> files = new LinkedHashSet<>();
|
||||
private final Set<File> extractedFiles = new LinkedHashSet<>();
|
||||
|
||||
@@ -119,10 +118,6 @@ public class Main {
|
||||
}
|
||||
|
||||
// Sort files for determinism
|
||||
projectFiles = projectFiles.stream()
|
||||
.sorted(AutoBuild.FILE_ORDERING)
|
||||
.collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
|
||||
|
||||
files = files.stream()
|
||||
.sorted(AutoBuild.FILE_ORDERING)
|
||||
.collect(Collectors.toCollection(() -> new LinkedHashSet<>()));
|
||||
@@ -256,11 +251,8 @@ public class Main {
|
||||
includes.add("**/.babelrc*.json");
|
||||
|
||||
|
||||
// extract TypeScript if `--typescript` or `--typescript-full` was specified
|
||||
if (getTypeScriptMode(ap) != TypeScriptMode.NONE) {
|
||||
addIncludesFor(includes, FileType.TYPESCRIPT);
|
||||
includes.add("**/*tsconfig*.json");
|
||||
}
|
||||
addIncludesFor(includes, FileType.TYPESCRIPT);
|
||||
includes.add("**/*tsconfig*.json");
|
||||
|
||||
// add explicit include patterns
|
||||
for (String pattern : ap.getZeroOrMore(P_INCLUDE))
|
||||
@@ -394,12 +386,6 @@ public class Main {
|
||||
return ap.has(P_EXPERIMENTAL) || ap.has(P_JSCRIPT) || ap.has(P_MOZ_EXTENSIONS);
|
||||
}
|
||||
|
||||
private static TypeScriptMode getTypeScriptMode(ArgsParser ap) {
|
||||
if (ap.has(P_TYPESCRIPT_FULL)) return TypeScriptMode.FULL;
|
||||
if (ap.has(P_TYPESCRIPT)) return TypeScriptMode.BASIC;
|
||||
return TypeScriptMode.NONE;
|
||||
}
|
||||
|
||||
private Path inferSourceRoot(ArgsParser ap) {
|
||||
List<File> files = getFilesArg(ap);
|
||||
Path sourceRoot = files.iterator().next().toPath().toAbsolutePath().getParent();
|
||||
@@ -430,7 +416,6 @@ public class Main {
|
||||
.withFileType(getFileType(ap))
|
||||
.withSourceType(ap.getEnum(P_SOURCE_TYPE, SourceType.class, SourceType.AUTO))
|
||||
.withExtractLines(ap.has(P_EXTRACT_PROGRAM_TEXT))
|
||||
.withTypeScriptMode(getTypeScriptMode(ap))
|
||||
.withTypeScriptRam(
|
||||
ap.has(P_TYPESCRIPT_RAM)
|
||||
? UnitParser.parseOpt(ap.getString(P_TYPESCRIPT_RAM), UnitParser.MEGABYTES)
|
||||
@@ -494,12 +479,6 @@ public class Main {
|
||||
&& (explicit || includeMatcher.matches(path) && !excludeMatcher.matches(path))) {
|
||||
files.add(normalizeFile(root));
|
||||
}
|
||||
|
||||
if (extractorConfig.getTypeScriptMode() == TypeScriptMode.FULL
|
||||
&& AutoBuild.treatAsTSConfig(root.getName())
|
||||
&& !excludeMatcher.matches(path)) {
|
||||
projectFiles.add(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.semmle.js.extractor;
|
||||
|
||||
/** The amount of information to extract from TypeScript files. */
|
||||
public enum TypeScriptMode {
|
||||
/** TypeScript files will not be extracted. */
|
||||
NONE,
|
||||
|
||||
/**
|
||||
* Only syntactic information will be extracted from TypeScript files.
|
||||
*
|
||||
* <p>This requires Node.js and the TypeScript compiler to be installed if the project contains
|
||||
* any TypeScript files.
|
||||
*/
|
||||
BASIC,
|
||||
|
||||
/** Extract as much as possible from TypeScript files. */
|
||||
FULL;
|
||||
}
|
||||
Reference in New Issue
Block a user