Documentation
¶
Overview ¶
Package cmd provides ...
Index ¶
- Constants
- Variables
- func AddFlags(rootCmd *cobra.Command)
- func BuildConfigFromFlags(cmd *cobra.Command, args []string) (*config.Config, error)
- func ExitCodeForError(err error) int
- func GetBuildDate() string
- func GetCommit() string
- func GetVersion() string
- func NewBaselineCommand() *cobra.Command
- func NewCheckCommand() *cobra.Command
- func NewRootCommand() *cobra.Command
- func NewStatsCommand() *cobra.Command
- func NewVersionCommand() *cobra.Command
- func PrintVersion()
- func RecommendThreshold(fileCount int) int
- type AcceptedDirective
- type AcceptedSet
- type CrawlOptions
- type FilterSource
- type FilterStats
- func (s *FilterStats) Breakdown() map[string]int
- func (s *FilterStats) FilteredBy(reason string) int
- func (s *FilterStats) Reasons() []gogenfilter.FilterReason
- func (s *FilterStats) Record(result gogenfilter.FilterResult)
- func (s *FilterStats) RecordWithSource(result gogenfilter.FilterResult, source FilterSource)
- func (s *FilterStats) SourceBreakdown() map[string]int
- func (s *FilterStats) TotalFiltered() int
- type GitignoreMatcher
- type SuppressionConfig
- type VersionInfo
Constants ¶
const ( ExitSuccess = 0 ExitGeneralError = 1 ExitConfigError = 2 ExitInternalError = 3 ExitInterrupted = 130 )
const ( // VendorDirPrefix is the vendor directory prefix for exclusion. VendorDirPrefix = "vendor" + string(filepath.Separator) // VendorDirInPath is the vendor directory marker when it appears in a path. VendorDirInPath = string(filepath.Separator) + VendorDirPrefix // DSStoreFile is the macOS Finder metadata file that should always be excluded. DSStoreFile = ".DS_Store" // GitDirPrefix is the Git directory prefix for exclusion. GitDirPrefix = ".git" + string(filepath.Separator) // GitDirInPath is the Git directory marker when it appears in a path. GitDirInPath = string(filepath.Separator) + GitDirPrefix // NodeModulesDirPrefix is the node_modules directory prefix for exclusion. NodeModulesDirPrefix = "node_modules" + string(filepath.Separator) // NodeModulesDirInPath is the node_modules directory marker when it appears in a path. NodeModulesDirInPath = string(filepath.Separator) + NodeModulesDirPrefix )
Directory exclusion constants.
Variables ¶
var ( Version = "dev" //nolint:gochecknoglobals // Build-time variables meant to be overridden Commit = "unknown" //nolint:gochecknoglobals Date = "unknown" //nolint:gochecknoglobals )
Version information - can be overridden during build.
Functions ¶
func BuildConfigFromFlags ¶
BuildConfigFromFlags extracts flag values and builds a merged configuration. This function handles the common config-building logic shared between run and stats commands.
func ExitCodeForError ¶ added in v0.4.0
ExitCodeForError maps an error to the appropriate process exit code. nil error returns ExitSuccess. Context cancellation returns ExitInterrupted. Config/validation errors return ExitConfigError. Everything else returns ExitGeneralError.
func GetVersion ¶
func GetVersion() string
GetVersion returns version information including build info.
func NewBaselineCommand ¶ added in v0.4.0
NewBaselineCommand creates the `baseline` subcommand that snapshots the currently-detected clones into a baseline file for later CI comparison.
func NewCheckCommand ¶ added in v0.4.0
NewCheckCommand creates the `check` subcommand that reports only new clones relative to a baseline, exiting non-zero if any are found. Designed for CI.
func NewRootCommand ¶
NewRootCommand creates the root Cobra command.
func NewStatsCommand ¶
NewStatsCommand creates the stats command.
func NewVersionCommand ¶ added in v0.4.0
NewVersionCommand creates the version subcommand.
func RecommendThreshold ¶ added in v0.5.0
RecommendThreshold suggests a threshold based on codebase size. Heuristic: <100 files -> 3, 100-1000 -> 5, 1000-5000 -> 7, >5000 -> 10.
Types ¶
type AcceptedDirective ¶ added in v0.5.0
type AcceptedDirective struct {
Line int // 1-indexed source line number where the directive appears
Hash string // optional group hash for precision matching (empty = match any group)
}
AcceptedDirective represents a single //art-dupl:accept comment in source code.
type AcceptedSet ¶ added in v0.5.0
type AcceptedSet struct {
// contains filtered or unexported fields
}
AcceptedSet tracks //art-dupl:accept directives across source files. It lazily scans files on first access and caches the result so each file is read at most once per run.
func NewAcceptedSet ¶ added in v0.5.0
func NewAcceptedSet(readFile func(string) ([]byte, error)) *AcceptedSet
NewAcceptedSet creates an AcceptedSet that uses the given file reader.
func (*AcceptedSet) IsAccepted ¶ added in v0.5.0
func (a *AcceptedSet) IsAccepted(group domain.ProcessedCloneGroup) bool
IsAccepted checks if any clone in the group has an accept directive within its line range or up to acceptDirectiveScanAbove lines above LineStart. A directive on line N accepts clones where (LineStart - acceptDirectiveScanAbove) <= N <= LineEnd. This matches user expectations: directives placed on the line above the clone (like every other linter) are honored. When the directive includes a hash (//art-dupl:accept <hash>), it only matches groups with that exact hash.
type CrawlOptions ¶
type CrawlOptions struct {
Ctx context.Context
Filter *gogenfilter.Filter
FilterStats *FilterStats
Includes generatorIncludes
IncludeVendor bool
IncludeNodeMods bool
FileCheck fileCheckFunc
Gitignore *GitignoreMatcher
FChan chan string
}
CrawlOptions contains the common options for crawling operations.
type FilterSource ¶ added in v0.5.0
type FilterSource string
FilterSource identifies which filtering mechanism caught a generated file.
const ( // FilterSourceGogenfilter: caught by gogenfilter's standard filename-gated // or content-based checks. FilterSourceGogenfilter FilterSource = "gogenfilter" // FilterSourceDefenseInDepth: caught by the content-based defense-in-depth // check (filterExcludedGenerated) that catches generated files lacking the // expected filename suffix (_templ.go, _sqlc.go, *.pb.go). FilterSourceDefenseInDepth FilterSource = "defense-in-depth" )
type FilterStats ¶ added in v0.2.0
type FilterStats struct {
// contains filtered or unexported fields
}
FilterStats holds aggregated filter statistics. Replaces the removed gogenfilter.FilterStats type — stats aggregation is now the caller's responsibility per gogenfilter's API redesign.
func NewFilterStats ¶ added in v0.2.0
func NewFilterStats(reasons []gogenfilter.FilterReason) *FilterStats
NewFilterStats creates a new FilterStats with the given filter reasons.
func (*FilterStats) Breakdown ¶ added in v0.2.0
func (s *FilterStats) Breakdown() map[string]int
Breakdown returns a defensive copy of the per-reason breakdown.
func (*FilterStats) FilteredBy ¶ added in v0.2.0
func (s *FilterStats) FilteredBy(reason string) int
FilteredBy returns the number of files filtered by the given reason.
func (*FilterStats) Reasons ¶ added in v0.2.0
func (s *FilterStats) Reasons() []gogenfilter.FilterReason
Reasons returns the filter reasons this tracker was configured with.
func (*FilterStats) Record ¶ added in v0.2.0
func (s *FilterStats) Record(result gogenfilter.FilterResult)
Record records a filter result from gogenfilter.
func (*FilterStats) RecordWithSource ¶ added in v0.5.0
func (s *FilterStats) RecordWithSource(result gogenfilter.FilterResult, source FilterSource)
RecordWithSource records a filter result with its source (gogenfilter or defense-in-depth), allowing stats output to distinguish how each file was caught.
func (*FilterStats) SourceBreakdown ¶ added in v0.5.0
func (s *FilterStats) SourceBreakdown() map[string]int
SourceBreakdown returns a defensive copy of the per-source breakdown, distinguishing files caught by gogenfilter vs the defense-in-depth content check.
func (*FilterStats) TotalFiltered ¶ added in v0.2.0
func (s *FilterStats) TotalFiltered() int
TotalFiltered returns the total number of filtered files.
type GitignoreMatcher ¶ added in v0.5.0
type GitignoreMatcher struct {
// contains filtered or unexported fields
}
GitignoreMatcher matches file paths against .gitignore patterns collected from the directory tree. It supports the most common gitignore syntax: simple names, globs (* and ?), directory-only (trailing /), anchored paths (leading /), and negation (!).
func LoadGitignore ¶ added in v0.5.0
func LoadGitignore(paths []string) *GitignoreMatcher
LoadGitignore walks up from startDir to find .gitignore files, then walks down through the analyzed paths to find nested ones. Returns nil if no .gitignore files are found.
func (*GitignoreMatcher) IsIgnored ¶ added in v0.5.0
func (m *GitignoreMatcher) IsIgnored(path string) bool
IsIgnored reports whether path should be ignored according to the loaded .gitignore rules. Rules are evaluated from root to deepest: later rules (more specific) can override earlier ones via negation.
type SuppressionConfig ¶ added in v0.4.0
type SuppressionConfig struct {
SuppressTestLow bool
TestThreshold int
MinLines int
AcceptDirectives *AcceptedSet
NoActionability bool
DisabledPatterns map[actionability.PatternLabel]bool
}
SuppressionConfig groups the filter thresholds used to suppress clone groups. Passing it as a single value avoids 3-parameter function signatures that are prone to argument-swap bugs.
type VersionInfo ¶ added in v0.4.0
type VersionInfo struct {
Version string `json:"version"`
Commit string `json:"commit"`
Date string `json:"date"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
Arch string `json:"arch"`
}
VersionInfo provides structured version information for CI tooling.
Source Files
¶
- accept_directive.go
- baseline_cmd.go
- baseline_printer.go
- config_builder.go
- diff_report.go
- doc.go
- dump_tokens.go
- exit_codes.go
- filter_stats.go
- flags.go
- gitignore.go
- progress.go
- recommend_threshold.go
- root.go
- run_all_modes.go
- run_analysis.go
- run_crawl.go
- run_flags.go
- run_hash.go
- run_output.go
- run_printer.go
- stats.go
- type_aware.go
- util.go
- version.go
- version_cmd.go