From 044dab81e98aa5b537f41f17857af6d6287afb33 Mon Sep 17 00:00:00 2001 From: Austin Flores Date: Fri, 4 Apr 2025 16:06:01 +0200 Subject: [PATCH 1/2] Should be using file glob and not regex --- src/scripts/occurances/CommandLine.ts | 12 ++++-------- .../occurances/processors/LOCLanguagesProcessor.ts | 12 ++++++------ src/scripts/projectConfig.ts | 8 ++++---- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/scripts/occurances/CommandLine.ts b/src/scripts/occurances/CommandLine.ts index 0e46361..8971a64 100644 --- a/src/scripts/occurances/CommandLine.ts +++ b/src/scripts/occurances/CommandLine.ts @@ -1,3 +1,4 @@ +import logger from "@/lib/logger"; import { execSync } from "child_process"; class CommandLine { @@ -28,16 +29,11 @@ class CommandLine { }); } - getLoc(fileRegex: string) { + getLoc(fileGlob: string) { // xargs will limit what it takes and thus we will end up with more than one line for total loc // for projects with a lot of files. This is fixed by using grep total and then summing those. - const loc = this.run( - `find ${this.absPath}/${this.projectDir} -name '${fileRegex}' | xargs wc -l|grep total| awk '{sum += $1} END {print sum}'` - ) - .toString() - .trim() - .split("\n"); - + const command = `find ${this.absPath}/${this.projectDir} -name '${fileGlob}' | xargs wc -l|grep total| awk '{sum += $1} END {print sum}'`; + const loc = this.run(command).toString().trim().split("\n"); return loc[0] ? parseInt(loc[0]) : 0; } diff --git a/src/scripts/occurances/processors/LOCLanguagesProcessor.ts b/src/scripts/occurances/processors/LOCLanguagesProcessor.ts index 576e5e3..352187d 100644 --- a/src/scripts/occurances/processors/LOCLanguagesProcessor.ts +++ b/src/scripts/occurances/processors/LOCLanguagesProcessor.ts @@ -10,12 +10,12 @@ const mainBranchNames = ["main", "master"]; */ class LOCLanguagesProcessor implements Processor { commandLine: CommandLine; - languageRegexes: { language: string; regex: string }[]; + languageGlobs: { language: string; glob: string }[]; mainBranchName: string | undefined; - constructor(commandLine: CommandLine, languageRegexes: { language: string; regex: string }[]) { + constructor(commandLine: CommandLine, languageGlobs: { language: string; glob: string }[]) { this.commandLine = commandLine; - this.languageRegexes = languageRegexes; + this.languageGlobs = languageGlobs; } analyses() { @@ -55,12 +55,12 @@ class LOCLanguagesProcessor implements Processor { const commit = commits[commitsTraversed]; this.commandLine.checkout(commit.hash); - this.languageRegexes.forEach((langRegex) => { - const loc = this.commandLine.getLoc(langRegex.regex); + this.languageGlobs.forEach((langGlob) => { + const loc = this.commandLine.getLoc(langGlob.glob); occurances.push({ type: AvailableAnalysisEnum.LOCLanguage, id: commit.hash, - section: langRegex.language, + section: langGlob.language, amount: loc, occurredAt: moment(commit.createdAt).toISOString(), }); diff --git a/src/scripts/projectConfig.ts b/src/scripts/projectConfig.ts index 4c89595..f69c22e 100644 --- a/src/scripts/projectConfig.ts +++ b/src/scripts/projectConfig.ts @@ -34,16 +34,16 @@ class ProjectConfig { return this.config[projectName]?.git; } - languageRegexes(projectName: string): { language: string; regex: string }[] { + languageRegexes(projectName: string): { language: string; glob: string }[] { return (this.config[projectName]?.languages || []) .map((language) => { if (language === "typescript") { - return { language, regex: ".tsx?" }; + return { language, glob: "*.tsx*" }; } else if (language === "ruby") { - return { language, regex: ".rb" }; + return { language, glob: "*.rb" }; } }) - .filter((item): item is { language: string; regex: string } => item !== undefined); + .filter((item): item is { language: string; glob: string } => item !== undefined); } projectDir(projectName: string) { From c851287d560d0d12056e0b530c1a25a7e17d4174 Mon Sep 17 00:00:00 2001 From: Austin Flores Date: Fri, 4 Apr 2025 16:07:16 +0200 Subject: [PATCH 2/2] Remove unneeded import --- src/scripts/occurances/CommandLine.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scripts/occurances/CommandLine.ts b/src/scripts/occurances/CommandLine.ts index 8971a64..ca182dc 100644 --- a/src/scripts/occurances/CommandLine.ts +++ b/src/scripts/occurances/CommandLine.ts @@ -1,4 +1,3 @@ -import logger from "@/lib/logger"; import { execSync } from "child_process"; class CommandLine {