processor/history_validation.go GO 85 lines View on github.com → Search inside
1// SPDX-License-Identifier: MIT23package processor45import (6	"errors"7	"fmt"8	"io"9	"strings"10)1112// validateHistoryFlags checks the global flag state for the history reports13// (--hotspots, --by-author, --timeline). Hard errors are returned and should14// abort the run; recoverable conditions are written to warnDst as a single15// line each and execution continues.16func validateHistoryFlags(warnDst io.Writer) error {17	if !Hotspots && !ByAuthor && !Timeline {18		return nil19	}2021	if HistoryDepth < 0 {22		return errors.New("--depth must be >= 0 (0 means entire history)")23	}2425	if Timeline && HistoryBuckets < 1 {26		return errors.New("--buckets must be >= 1")27	}2829	if len(DirFilePaths) > 1 {30		_, _ = fmt.Fprintf(31			warnDst,32			"history reports run against a single repository; ignoring extra paths: %s\n",33			strings.Join(DirFilePaths[1:], ", "),34		)35	}3637	ignored := collectIgnoredHistoryFlags()38	if len(ignored) > 0 {39		_, _ = fmt.Fprintf(40			warnDst,41			"history reports ignore these flags: %s (they apply to the working-tree counter only)\n",42			strings.Join(ignored, ", "),43		)44	}4546	return nil47}4849// collectIgnoredHistoryFlags returns the CLI flag names that were set but50// have no effect under a history report. Order matches the user-facing51// flag list in --help to keep the warning readable.52func collectIgnoredHistoryFlags() []string {53	var ignored []string5455	add := func(active bool, name string) {56		if active {57			ignored = append(ignored, name)58		}59	}6061	add(Files, "--by-file")62	add(UlocMode, "--uloc")63	add(Dryness, "--dryness")64	add(MaxMean, "--character")65	add(Duplicates, "--no-duplicates")66	add(MinifiedGenerated, "--min-gen")67	add(Minified, "--min")68	add(Generated, "--gen")69	add(IgnoreMinifiedGenerate, "--no-min-gen")70	add(IgnoreMinified, "--no-min")71	add(IgnoreGenerated, "--no-gen")72	add(Cocomo, "--no-cocomo")73	add(Locomo, "--locomo")74	add(CostComparison, "--cost-comparison")75	add(SLOCCountFormat, "--sloccount-format")76	add(NoLarge, "--no-large")7778	sort := strings.ToLower(strings.TrimSpace(SortBy))79	if sort != "" && sort != "files" {80		ignored = append(ignored, "--sort")81	}8283	return ignored84}

Code quality findings 3

Blank identifier discarding results; verify intentional ignoring of return values
warning correctness blank-identifier-discard
_, _ = fmt.Fprintf(
Blank identifier discarding results; verify intentional ignoring of return values
warning correctness blank-identifier-discard
_, _ = fmt.Fprintf(
Multiple appends without pre-allocation; use make() with capacity when size is known
info performance append-without-prealloc
ignored = append(ignored, "--sort")

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.