refactor: extract basename helper to replace repeated split/pop pattern

The same filePath.split("/").pop() ?? filePath expression appeared three times across addFile, addFileWithAnalysis, and addNonCodeFile. A private static helper centralises the logic and makes call sites easier to read.
This commit is contained in:
Nikola Chetelyazov
2026-04-13 09:35:55 +03:00
Unverified
parent a89555d369
commit 82b1d06777
@@ -135,13 +135,17 @@ export class GraphBuilder {
this.gitHash = gitHash;
}
private static basename(filePath: string): string {
return GraphBuilder.basename(filePath);
}
addFile(filePath: string, meta: FileMeta): void {
const lang = detectLanguage(filePath);
if (lang !== "unknown") {
this.languages.add(lang);
}
const name = filePath.split("/").pop() ?? filePath;
const name = GraphBuilder.basename(filePath);
const id = `file:${filePath}`;
this.nodeIds.add(id);
@@ -166,7 +170,7 @@ export class GraphBuilder {
this.languages.add(lang);
}
const fileName = filePath.split("/").pop() ?? filePath;
const fileName = GraphBuilder.basename(filePath);
const fileId = `file:${filePath}`;
// Create the file node
@@ -258,7 +262,7 @@ export class GraphBuilder {
addNonCodeFile(filePath: string, meta: NonCodeFileMeta): void {
const lang = detectLanguage(filePath);
if (lang !== "unknown") this.languages.add(lang);
const name = filePath.split("/").pop() ?? filePath;
const name = GraphBuilder.basename(filePath);
const id = `${meta.nodeType ?? "file"}:${filePath}`;
this.nodeIds.add(id);
this.nodes.push({