From 82b1d06777cd0eca9209a8879034fd0c62842e76 Mon Sep 17 00:00:00 2001 From: Nikola Chetelyazov Date: Mon, 13 Apr 2026 09:35:55 +0300 Subject: [PATCH] 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. --- .../packages/core/src/analyzer/graph-builder.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/understand-anything-plugin/packages/core/src/analyzer/graph-builder.ts b/understand-anything-plugin/packages/core/src/analyzer/graph-builder.ts index fdb8f48..d43e9e0 100644 --- a/understand-anything-plugin/packages/core/src/analyzer/graph-builder.ts +++ b/understand-anything-plugin/packages/core/src/analyzer/graph-builder.ts @@ -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({