Skip to content

Commit 9bf7f71

Browse files
Small refactorings
1 parent 00f301f commit 9bf7f71

File tree

6 files changed

+31
-16
lines changed

6 files changed

+31
-16
lines changed

java/src/main/resources/META-INF/jqassistant-plugin.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<jqassistant-plugin xmlns="http://schema.jqassistant.org/plugin/v1.10"
22
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://schema.jqassistant.org/plugin/v1.10 https://schema.jqassistant.org/plugin/jqassistant-plugin-v1.8.xsd"
4-
name="jQAssistant Typescript Plugin" id="jqassistant.plugin.typescript">
4+
id="jqassistant.plugin.typescript"
5+
name="jQAssistant Typescript Plugin"
6+
version="${project.version}">
57
<description>Provides a scanner for Typescript.</description>
68
<model>
79
<class>org.jqassistant.plugin.typescript.api.model.core.AccessorPropertyDescriptor</class>

typescript/src/core/processors/type.utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { ModulePathUtils } from "../utils/modulepath.utils";
5353
import { DependencyResolutionProcessor } from "./dependency-resolution.processor";
5454
import { NodeUtils } from "../utils/node.utils";
5555
import path from "path";
56+
import { FileUtils } from "../utils/file.utils";
5657

5758
/**
5859
* Returns the type for a given class property (with a non-computed name)
@@ -361,7 +362,7 @@ function parseType(processingContext: ProcessingContext, type: Type, node: Node,
361362
// normalize TypeChecker FQN and determine if type is part of the project
362363
const sourceFile = symbol?.valueDeclaration?.getSourceFile() ?? symbol?.declarations?.find((d) => !!d.getSourceFile())?.getSourceFile();
363364
const isStandardLibrary = !!sourceFile && globalContext.services.program.isSourceFileDefaultLibrary(sourceFile);
364-
const relativeSrcPath = !!sourceFile ? path.relative(globalContext.projectInfo.rootPath, sourceFile.fileName).replace(/\\/g, "/") : undefined;
365+
const relativeSrcPath = !!sourceFile ? FileUtils.normalizePath(path.relative(globalContext.projectInfo.rootPath, sourceFile.fileName)) : undefined;
365366
const isExternal = !!sourceFile && (globalContext.services.program.isSourceFileFromExternalLibrary(sourceFile) || relativeSrcPath!.startsWith("node_modules"));
366367

367368
let normalizedFqn = new FQN("");

typescript/src/core/utils/modulepath.utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class ModulePathUtils {
2525
static getPathType(path: string): PathType {
2626
if (p.isAbsolute(path)) {
2727
return "absolute";
28-
} else if (path.startsWith(".") && !path.replace(/\\/g, "/").startsWith("./node_modules")) {
28+
} else if (path.startsWith(".") && !FileUtils.normalizePath(path).startsWith("./node_modules")) {
2929
return "relative";
3030
} else {
3131
return "node";
@@ -47,10 +47,10 @@ export class ModulePathUtils {
4747
} else {
4848
let relPath;
4949
if (pathType === "absolute") {
50-
relPath = p.relative(projectPath, path).replace(/\\/g, "/");
50+
relPath = FileUtils.normalizePath(p.relative(projectPath, path));
5151
} else {
5252
if (!originPath) throw new Error("originPath is required if path is relative");
53-
relPath = p.relative(projectPath, p.resolve(projectPath, originPath.slice(0, originPath.lastIndexOf("/")), path)).replace(/\\/g, "/");
53+
relPath = FileUtils.normalizePath(p.relative(projectPath, p.resolve(projectPath, originPath.slice(0, originPath.lastIndexOf("/")), path)));
5454
}
5555

5656
if (!relPath.startsWith(".")) {
@@ -122,7 +122,7 @@ export class ModulePathUtils {
122122

123123
// normalize paths on Windows platforms
124124
if(process.platform === "win32") {
125-
sourceFilePath = sourceFilePath.replace(/\\/g, "/");
125+
sourceFilePath = FileUtils.normalizePath(sourceFilePath);
126126
}
127127

128128
// remove index.* filename from FQN path
@@ -135,7 +135,7 @@ export class ModulePathUtils {
135135
} else {
136136
let sourceFilePath = fs.realpathSync.native(sourceFilePathAbsolute);
137137
if(process.platform === "win32") {
138-
sourceFilePath = sourceFilePath.replace(/\\/g, "/");
138+
sourceFilePath = FileUtils.normalizePath(sourceFilePath);
139139
}
140140
return this.toFQN(sourceFilePath).globalFqn + "." + tcFQN;
141141
}
@@ -147,8 +147,8 @@ export class ModulePathUtils {
147147
*/
148148
static toFQN(globalPath: string, localPath?: string): FQN {
149149
const indexSourceFileRegEx = /\/index\.\w+$/;
150-
const basicGlobalFQN = '"' + (globalPath.replace(/\\/g, "/")).replace(indexSourceFileRegEx, "") + '"';
151-
const basicLocalFQN = localPath ? '"' + (localPath.replace(/\\/g, "/")).replace(indexSourceFileRegEx, "") + '"' : "";
150+
const basicGlobalFQN = '"' + (FileUtils.normalizePath(globalPath)).replace(indexSourceFileRegEx, "") + '"';
151+
const basicLocalFQN = localPath ? '"' + (FileUtils.normalizePath(localPath)).replace(indexSourceFileRegEx, "") + '"' : "";
152152

153153
return new FQN(
154154
basicGlobalFQN,

typescript/src/core/utils/node.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class NodeUtils {
3030

3131
let currentPath = packagePath;
3232
while (currentPath !== projectRootPath && !path.relative(projectRootPath, currentPath).startsWith("..")) {
33-
const allFiles = FileUtils.getAllFiles(currentPath).map((f) => f.replace(/\\/g, "/"));
33+
const allFiles = FileUtils.getAllFiles(currentPath).map((f) => FileUtils.normalizePath(f));
3434
for (const file of allFiles) {
3535
if (path.basename(file) === "package.json") {
3636
const data = fs.readFileSync(file, "utf8");
@@ -68,14 +68,14 @@ export class NodeUtils {
6868
tsResolvedModule = module.resolvedModule?.resolvedFileName;
6969
} catch (e) {}
7070
if (tsResolvedModule) {
71-
return tsResolvedModule.replace(/\\/g, "/");
71+
return FileUtils.normalizePath(tsResolvedModule);
7272
} else {
7373
let jsResolvedModule: string | undefined;
7474
try {
7575
jsResolvedModule = require.resolve(importPath, { paths: [projectPath] });
7676
} catch (e) {}
7777
if (jsResolvedModule) {
78-
return jsResolvedModule.replace(/\\/g, "/");
78+
return FileUtils.normalizePath(jsResolvedModule);
7979
} else {
8080
throw new Error(`Could not resolve import: ${importPath}`);
8181
}

typescript/src/core/utils/project.utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class ProjectUtils {
7878
if(tsConfig.projectReferences) {
7979
for (const ref of tsConfig.projectReferences) {
8080
const subProjectInfos = this.getProjectInfo(ref.path);
81-
subProjectPaths.push(...subProjectInfos.map(spi => spi.projectPath.replace(/\\/g, "/")));
81+
subProjectPaths.push(...subProjectInfos.map(spi => FileUtils.normalizePath(spi.projectPath)));
8282
result.push(...subProjectInfos);
8383
}
8484
}
@@ -90,10 +90,10 @@ export class ProjectUtils {
9090
}
9191

9292
result.push({
93-
rootPath: rootPath.replace(/\\/g, "/"),
94-
projectPath: projectPath.replace(/\\/g, "/"),
93+
rootPath: FileUtils.normalizePath(rootPath),
94+
projectPath: FileUtils.normalizePath(projectPath),
9595
subProjectPaths: subProjectPaths,
96-
sourceFilePaths: tsConfig.fileNames.map(fn => fn.replace(/\\/g, "/"))
96+
sourceFilePaths: tsConfig.fileNames.map(fn => FileUtils.normalizePath(fn))
9797
});
9898

9999
return result;

typescript/src/core/utils/traverser.utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import { TraverserContext } from "../traverser";
88

99
/**
1010
* Tries to find an appropriate `Traverser` for the given node and calls its `traverse` method on the node.
11+
*
12+
* @param node child node of the node of the current processing context
13+
* @param traverserContext `TraverserContext` containing the property name of provided child node
14+
* @param parentNode/unusedProcessingContext current processing context
15+
* @param processors processors provided to a traverser
16+
* @param conceptMaps array of `ConceptMap`s to which extracted child concepts will be added
1117
* @returns the concepts generated for the node and/or its children or `undefined` if no `Traverser` could be found
1218
*/
1319
export function runTraverserForNode(
@@ -38,6 +44,12 @@ export function runTraverserForNode(
3844
/**
3945
* Runs`runTraverserForNode` for the given nodes.
4046
* Also provides index information of the parent node property to the traversers.
47+
*
48+
* @param nodes child nodes of the node of the current processing context
49+
* @param traverserContext `TraverserContext` containing the property name of provided child nodes
50+
* @param processingContext current processing context
51+
* @param processors processors provided to a traverser
52+
* @param conceptMaps array of `ConceptMap`s to which extracted child concepts will be added
4153
*/
4254
export function runTraverserForNodes(
4355
nodes: (Node | null)[],

0 commit comments

Comments
 (0)