From 96e67df82a3244c451b36cdf1a0a7a2ae2f04c03 Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Sun, 28 Apr 2024 20:52:35 -0700 Subject: [PATCH 1/2] More concise, and tab-delimited output Also gofmt. --- gosloc.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gosloc.go b/gosloc.go index 14b4658..6f16cb8 100644 --- a/gosloc.go +++ b/gosloc.go @@ -36,7 +36,7 @@ func parseArgs() (path string, vendor bool) { continue } // Add a / so it works with symlinks - path = filepath.Clean(val)+"/" + path = filepath.Clean(val) + "/" } if path == "" { @@ -116,7 +116,7 @@ func main() { } } - if scanner.Err() != nil && scanner.Err() == bufio.ErrTooLong{ + if scanner.Err() != nil && scanner.Err() == bufio.ErrTooLong { fmt.Printf("- Skipping %s because of unusually long lines\n", path) return nil } @@ -135,14 +135,14 @@ func main() { } if files == 0 { - fmt.Printf("No go source files found in %s\n", path) + fmt.Printf("No Go source files found in %s\n", path) } else { - total := float64(code+comments+blanks) - fmt.Printf("Scanned %d go files in %s:\n", files, path) - fmt.Printf(" Source lines: %d (%.1f%%)\n", code, float64(code)/total*100) - fmt.Printf(" Comment lines: %d (%.1f%%)\n", comments, float64(comments)/total*100) - fmt.Printf(" Blank lines: %d (%.1f%%)\n", blanks, float64(blanks)/total*100) - fmt.Printf(" Test lines: %d (%.2f per line of code)\n", tests, float64(tests)/float64(code)) - fmt.Printf(" Total file size: %.2f Mb\n", float64(byteSize)/(1024.0*1024.0)) + total := code + comments + blanks + totalF := float64(total) + fmt.Printf("Source\t%8d\t%4.1f%%\n", code, float64(code)/totalF*100) + fmt.Printf("Comment\t%8d\t%4.1f%%\n", comments, float64(comments)/totalF*100) + fmt.Printf("Blank\t%8d\t%4.1f%%\t\n", blanks, float64(blanks)/totalF*100) + fmt.Printf("Test\t%8d\t%4.1f per line of code\n", tests, float64(tests)/float64(code)) + fmt.Printf("Total\t%8d\t%d files\t%.1f KiB\n", total, files, float64(byteSize)/1024.0) } } From 3d634a8ba850b0c86088003363dda780f8f6e527 Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Fri, 3 May 2024 22:44:41 -0700 Subject: [PATCH 2/2] Add go.mod --- go.mod | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f96af14 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/noncombatant/gosloc + +go 1.22.1