From f3bcd2cefe7f0432381b43e34fdc2c29803618c9 Mon Sep 17 00:00:00 2001 From: dmkjfs Date: Wed, 15 Oct 2025 15:54:12 +0300 Subject: [PATCH 1/3] BUGFIX: panicking proceeding a non-existing path (#3) --- cmd/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 28acc49..90114fc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -17,9 +17,9 @@ func main () { response, err := core.GetStatistics(path) if err != nil { - fmt.Printf("Path %s is not found\n", path) + fmt.Printf("ERROR: path \"%s\" is not found!!!\n", path) + } else { + fmt.Print(internal.GetTable(response.Items)) } - - fmt.Print(internal.GetTable(response.Items)) } } From 69cbc69803e684cf3db1a7b2a7828cb6bb11b211 Mon Sep 17 00:00:00 2001 From: dmkjfs Date: Wed, 15 Oct 2025 16:13:51 +0300 Subject: [PATCH 2/3] ENHANCEMENT: improve utils (#4) --- cmd/main.go | 2 +- internal/utils.go | 39 ++++++++++++++++++++++----------------- internal/utils_test.go | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 90114fc..97c1acc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -19,7 +19,7 @@ func main () { if err != nil { fmt.Printf("ERROR: path \"%s\" is not found!!!\n", path) } else { - fmt.Print(internal.GetTable(response.Items)) + fmt.Print(internal.GetTable(response.Items, 5, 3, 5)) } } } diff --git a/internal/utils.go b/internal/utils.go index 74ac671..e7ee504 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -8,39 +8,44 @@ import ( core "github.com/statloc/core" ) -func GetTable(items map[string]*core.TableItem) string { +func GetTable( + items map[string]*core.TableItem, + titleLength int, + LOCLength int, + filesLength int, +) string { // im sorry for that - maxTitleLength, maxLOCLength, maxFilesLength := 5, 3, 5 + column1width, column2width, column3width := titleLength, LOCLength, filesLength for title, item := range items { - if len(title) > maxTitleLength { - maxTitleLength = len(title) + if len(title) > int(column1width) { + column1width = len(title) } LOC := strconv.FormatUint(item.LOC, 10) - if len(LOC) > maxLOCLength { - maxLOCLength = len(LOC) + if len(LOC) > column2width { + column2width= len(LOC) } files := strconv.FormatUint(item.Files, 10) - if len(files) > maxFilesLength { - maxFilesLength = len(files) + if len(files) > column3width { + column3width= len(files) } } separator := fmt.Sprintf( "+-%s-+-%s-+-%s-+\n", - strings.Repeat("-", maxTitleLength), - strings.Repeat("-", maxLOCLength), - strings.Repeat("-", maxFilesLength), + strings.Repeat("-", column1width), + strings.Repeat("-", column2width), + strings.Repeat("-", column3width), ) result := fmt.Sprint( separator, fmt.Sprintf( "| Title%s | LOC%s | Files%s |\n", - strings.Repeat(" ", maxTitleLength - 5), - strings.Repeat(" ", maxLOCLength - 3), - strings.Repeat(" ", maxFilesLength - 5), + strings.Repeat(" ", column1width - titleLength), + strings.Repeat(" ", column2width - LOCLength), + strings.Repeat(" ", column3width - filesLength), ), separator, ) @@ -48,9 +53,9 @@ func GetTable(items map[string]*core.TableItem) string { for title, item := range items { result += fmt.Sprintf( "| %s%s | %d%s | %d%s |\n", - title, strings.Repeat(" ", maxTitleLength - len(title)), - item.LOC, strings.Repeat(" ", maxLOCLength - len(strconv.FormatUint(item.LOC, 10))), - item.Files, strings.Repeat(" ", maxFilesLength - len(strconv.FormatUint(item.Files, 10))), + title, strings.Repeat(" ", column1width - len(title)), + item.LOC, strings.Repeat(" ", column2width - len(strconv.FormatUint(item.LOC, 10))), + item.Files, strings.Repeat(" ", column3width - len(strconv.FormatUint(item.Files, 10))), ) } diff --git a/internal/utils_test.go b/internal/utils_test.go index 742c496..710efe5 100644 --- a/internal/utils_test.go +++ b/internal/utils_test.go @@ -16,7 +16,7 @@ func TestGetTable(t *testing.T) { defer file.Close() // nolint:errcheck statistics, _ := core.GetStatistics("../testdata") - table := internal.GetTable(statistics.Items) + table := internal.GetTable(statistics.Items, 5, 3, 5) // go line by line scanner := bufio.NewScanner(file) From f1932317b66d4aa5bf540d38c4f629c346fd562b Mon Sep 17 00:00:00 2001 From: dmkjfs Date: Wed, 15 Oct 2025 16:21:26 +0300 Subject: [PATCH 3/3] CHORE: update `Makefile` (#5) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5d91e0d..a3e5b6f 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ build: test: go test ./... -coverage: +cov: go test -coverprofile=.coverage ./... clean: