mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Merge pull request #18622 from asgerf/js/typescript-tsconfig-names
JS: Treat more file patterns as tsconfig-like files
This commit is contained in:
@@ -394,7 +394,7 @@ public class AutoBuild {
|
||||
for (FileType filetype : defaultExtract)
|
||||
for (String extension : filetype.getExtensions()) patterns.add("**/*" + extension);
|
||||
|
||||
// include .eslintrc files, .xsaccess files, package.json files,
|
||||
// include .eslintrc files, .xsaccess files, package.json files,
|
||||
// tsconfig.json files, and codeql-javascript-*.json files
|
||||
patterns.add("**/.eslintrc*");
|
||||
patterns.add("**/.xsaccess");
|
||||
@@ -895,7 +895,7 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path>
|
||||
// For named packages, find the main file.
|
||||
String name = packageJson.getName();
|
||||
if (name != null) {
|
||||
Path entryPoint = null;
|
||||
Path entryPoint = null;
|
||||
try {
|
||||
entryPoint = guessPackageMainFile(path, packageJson, FileType.TYPESCRIPT.getExtensions());
|
||||
if (entryPoint == null) {
|
||||
@@ -1108,6 +1108,10 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path>
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean treatAsTSConfig(String basename) {
|
||||
return basename.contains("tsconfig.") && basename.endsWith(".json");
|
||||
}
|
||||
|
||||
private void findFilesToExtract(
|
||||
FileExtractor extractor, final Set<Path> filesToExtract, final List<Path> tsconfigFiles)
|
||||
throws IOException {
|
||||
@@ -1140,7 +1144,7 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path>
|
||||
|
||||
// extract TypeScript projects from 'tsconfig.json'
|
||||
if (typeScriptMode == TypeScriptMode.FULL
|
||||
&& file.getFileName().endsWith("tsconfig.json")
|
||||
&& treatAsTSConfig(file.getFileName().toString())
|
||||
&& !excludes.contains(file)
|
||||
&& isFileIncluded(file)) {
|
||||
tsconfigFiles.add(file);
|
||||
|
||||
@@ -539,7 +539,7 @@ public class Main {
|
||||
}
|
||||
|
||||
if (extractorConfig.getTypeScriptMode() == TypeScriptMode.FULL
|
||||
&& root.getName().equals("tsconfig.json")
|
||||
&& AutoBuild.treatAsTSConfig(root.getName())
|
||||
&& !excludeMatcher.matches(path)) {
|
||||
projectFiles.add(root);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
category: majorAnalysis
|
||||
---
|
||||
* TypeScript extraction is now better at analyzing projects where the main `tsconfig.json` file does not include any
|
||||
source files, but references other `tsconfig.json`-like files that do include source files.
|
||||
@@ -0,0 +1,4 @@
|
||||
export function main(foo: string) {
|
||||
let x = foo;
|
||||
console.log(x);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
types
|
||||
| (...data: any[]) => void |
|
||||
| (foo: string) => void |
|
||||
| Console |
|
||||
| any |
|
||||
| any[] |
|
||||
| string |
|
||||
| void |
|
||||
jsonFiles
|
||||
@@ -0,0 +1,5 @@
|
||||
import javascript
|
||||
|
||||
query predicate types(Type type) { any() }
|
||||
|
||||
query predicate jsonFiles(File file) { file.getExtension() = "json" }
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"include": [],
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.foo.json" },
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user