Skip to content

Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.

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

Nikola Chetelyazov82b1d06777cd
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 fdb8f484..d43e9e0e 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({