From c781118fcd6bab736274a742be9368711e6a23e9 Mon Sep 17 00:00:00 2001 From: Iain Date: Sun, 4 Oct 2026 15:08:48 +0100 Subject: [PATCH 1/2] refactor: keep the --report-skip section list in one place --- config.go | 2 +- processor/report.go | 15 ++------------- processor/report_render.go | 5 +++-- processor/report_test.go | 14 +++++--------- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/config.go b/config.go index 6049947b8..c9efdae25 100644 --- a/config.go +++ b/config.go @@ -366,7 +366,7 @@ func registerFlags(flags *pflag.FlagSet, b *flagBindings) { // ReportOut to processor.DefaultReportName to tell "bare flag" apart from an // explicit path, so the two must stay in sync. flags.Lookup("report").NoOptDefVal = processor.DefaultReportName - flags.StringVar(strVar(&processor.ReportSkip), "report-skip", "", "comma-separated sections to omit (cocomo,locomo,hotspots,coupling,authors,timeline,files,uloc,linelength,card)") + flags.StringVar(strVar(&processor.ReportSkip), "report-skip", "", "comma-separated sections to omit ("+strings.Join(processor.ReportSkipSections, ",")+")") flags.StringVar(strVar(&processor.ReportTitle), "report-title", "", "override the repo name shown in the report banner") flags.StringSliceVarP(sliceVar(&processor.AllowListExtensions), "include-ext", "i", []string{}, "limit to file extensions [comma separated list: e.g. go,java,js]") flags.StringSliceVarP(sliceVar(&processor.ExcludeListExtensions), "exclude-ext", "x", []string{}, "ignore file extensions (overrides include-ext) [comma separated list: e.g. go,java,js]") diff --git a/processor/report.go b/processor/report.go index 79c22def2..9dd825892 100644 --- a/processor/report.go +++ b/processor/report.go @@ -42,22 +42,11 @@ var ReportSkipNames = map[string]bool{} // (spec 05). Empty means "auto-detect". var ReportTitle = "" -// reportSkipRecognised is the set of section names --report-skip accepts. +// ReportSkipSections is the list of section names --report-skip accepts. // Kept here (next to ReportSkipped) so future template authors can find the // authoritative list in one place. Names must match what the report template // and CollectReportData branch on. Spec 05 fixes this set. -var reportSkipRecognised = map[string]bool{ - "cocomo": true, - "locomo": true, - "hotspots": true, - "coupling": true, - "authors": true, - "timeline": true, - "files": true, - "uloc": true, - "linelength": true, - "card": true, -} +var ReportSkipSections = []string{"cocomo", "locomo", "hotspots", "coupling", "authors", "timeline", "files", "uloc", "linelength", "card"} // ReportSkipped reports whether the given section name was listed in // --report-skip. Section names are case-insensitive — callers can pass diff --git a/processor/report_render.go b/processor/report_render.go index 9f05f0157..d8c00f32a 100644 --- a/processor/report_render.go +++ b/processor/report_render.go @@ -12,6 +12,7 @@ import ( "math" "net/url" "os" + "slices" "sort" "strings" "sync" @@ -65,8 +66,8 @@ func parseReportSkipTo(raw string, warnW io.Writer) { if name == "" { continue } - if !reportSkipRecognised[name] { - _, _ = fmt.Fprintf(warnW, "warning: --report-skip: unknown section %q (recognised: cocomo, locomo, hotspots, coupling, authors, timeline, files, uloc, linelength, card)\n", name) + if !slices.Contains(ReportSkipSections, name) { + _, _ = fmt.Fprintf(warnW, "warning: --report-skip: unknown section %q (recognised: %s)\n", name, strings.Join(ReportSkipSections, ", ")) } ReportSkipNames[name] = true } diff --git a/processor/report_test.go b/processor/report_test.go index 1c3ba7612..c1feb96f4 100644 --- a/processor/report_test.go +++ b/processor/report_test.go @@ -10,6 +10,7 @@ import ( "math" "os" "path/filepath" + "slices" "strings" "testing" "time" @@ -329,9 +330,9 @@ func TestParseReportSkipKnownNames(t *testing.T) { withReportSkipReset(t) var warn bytes.Buffer - parseReportSkipTo("Cocomo, Locomo, hotspots, AUTHORS, timeline, files, uloc, linelength, card", &warn) + parseReportSkipTo(strings.ToUpper(strings.Join(ReportSkipSections, ", ")), &warn) - for _, name := range []string{"cocomo", "locomo", "hotspots", "authors", "timeline", "files", "uloc", "linelength", "card"} { + for _, name := range ReportSkipSections { if !ReportSkipped(name) { t.Errorf("ReportSkipped(%q) = false, want true after parseReportSkip", name) } @@ -528,13 +529,8 @@ func TestReportImplicitlyEnablesULOCAndLineLength(t *testing.T) { // add or drop one without updating the spec. func TestReportSkipRecognisedListMatchesSpec(t *testing.T) { want := []string{"cocomo", "locomo", "hotspots", "coupling", "authors", "timeline", "files", "uloc", "linelength", "card"} - if len(reportSkipRecognised) != len(want) { - t.Errorf("reportSkipRecognised size = %d, want %d", len(reportSkipRecognised), len(want)) - } - for _, name := range want { - if !reportSkipRecognised[name] { - t.Errorf("reportSkipRecognised missing %q", name) - } + if !slices.Equal(ReportSkipSections, want) { + t.Errorf("ReportSkipSections = %v, want %v", ReportSkipSections, want) } } From 408cf99288b19581ea88a07f712ab0187c61bfcd Mon Sep 17 00:00:00 2001 From: Iain Date: Sun, 4 Oct 2026 15:08:48 +0100 Subject: [PATCH 2/2] fix: point the --wide help at --no-complexity --- README.md | 2 +- config.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 16f10df66..02d24c25d 100644 --- a/README.md +++ b/README.md @@ -396,7 +396,7 @@ Flags: -u, --uloc calculate the number of unique lines of code (ULOC) for the project -v, --verbose verbose output --version version for scc - -w, --wide wider output with additional statistics (implies --complexity) + -w, --wide wider output with additional statistics (overrides --no-complexity) ``` Output should look something like the below for the redis project diff --git a/config.go b/config.go index c9efdae25..a429645df 100644 --- a/config.go +++ b/config.go @@ -433,7 +433,7 @@ func registerFlags(flags *pflag.FlagSet, b *flagBindings) { flags.StringVarP(strVar(&processor.SortBy), "sort", "s", "files", "column to sort by [files, name, lines, blanks, code, comments, complexity]") flags.BoolVarP(boolVar(&processor.Trace), "trace", "t", false, "enable trace output (not recommended when processing multiple files)") flags.BoolVarP(boolVar(&processor.Verbose), "verbose", "v", false, "verbose output") - flags.BoolVarP(boolVar(&processor.More), "wide", "w", false, "wider output with additional statistics (implies --complexity)") + flags.BoolVarP(boolVar(&processor.More), "wide", "w", false, "wider output with additional statistics (overrides --no-complexity)") flags.BoolVar(boolVar(&processor.NoLarge), "no-large", false, "ignore files over certain byte and line size set by large-line-count and large-byte-count") flags.BoolVar(boolVar(&processor.IncludeSymLinks), "include-symlinks", false, "if set will count symlink files") flags.Int64Var(int64Var(&processor.LargeLineCount), "large-line-count", 40000, "number of lines a file can contain before being removed from output")