Documentation
¶
Index ¶
- Constants
- Variables
- func SaveConfig(config *Config, filename string) error
- func ValidateConfig(cfg *Config) error
- func ValidateDetectionMethods(methods []DetectionMethod) error
- type Config
- type DetectionConfig
- type DetectionMethod
- type DetectionMethods
- type DiffMode
- type FileType
- type OutputFormat
- type SortCriteria
Constants ¶
const DefaultThreshold = 15
DefaultThreshold is the default minimum token sequence size for clone detection.
Variables ¶
var ( ErrInvalidDetectionMethod = errors.New("invalid detection method") ErrInvalidType = errors.New("invalid type") ErrInvalidThreshold = errors.New("threshold must be >= 1") ErrThresholdTooLarge = errors.New("threshold too large (max 1000)") )
Static errors for config validation.
var ErrInvalidFileType = errors.New("invalid file type")
ErrInvalidFileType is returned when a file type value is invalid.
var ErrInvalidOutputFormat = errors.New("invalid output format")
ErrInvalidOutputFormat indicates an unsupported output format was requested.
Functions ¶
func SaveConfig ¶
SaveConfig saves configuration to file.
func ValidateConfig ¶
ValidateConfig validates the configuration.
func ValidateDetectionMethods ¶
func ValidateDetectionMethods(methods []DetectionMethod) error
ValidateDetectionMethods validates a list of detection methods.
Types ¶
type Config ¶
type Config struct {
// Threshold sets the minimum token sequence size to consider as duplicate
Threshold int `json:"threshold,omitempty"`
// IncludeVendor includes vendor directory in analysis
IncludeVendor bool `json:"includeVendor,omitempty"`
// IncludeNodeModules includes node_modules directory in hash-based analysis.
// By default, node_modules is excluded in hash detection mode to avoid
// processing large dependency directories. Set to true to include them.
IncludeNodeModules bool `json:"includeNodeModules,omitempty"`
// FilesFromStdin reads file paths from stdin when true
FilesFromStdin bool `json:"filesFromStdin,omitempty"`
// OutputFormat sets the output format with type safety
OutputFormat OutputFormat `json:"outputFormat,omitempty"`
// Verbose enables verbose output
Verbose bool `json:"verbose,omitempty"`
// Paths specifies the paths to analyze
Paths []string `json:"paths,omitempty"`
// IgnoreFiles specifies file patterns to ignore
IgnoreFiles []string `json:"ignoreFiles,omitempty"`
// MaxChildrenSerial sets the maximum children serial for large slices
MaxChildrenSerial int `json:"maxChildrenSerial,omitempty"`
// OutputFile specifies the output file (if not stdout)
OutputFile string `json:"outputFile,omitempty"`
// SortBy specifies sorting criteria for clone groups
SortBy SortCriteria `json:"sortBy,omitempty"`
// DetectionMethods specifies which detection methods to use
DetectionMethods DetectionMethods `json:"detectionMethods,omitempty"`
// Profile enables performance profiling output
Profile bool `json:"profile,omitempty"`
// Timeout specifies maximum execution time in seconds (0 = no timeout)
Timeout int `json:"timeout,omitempty"`
// IncludeSQLC includes sqlc.dev generated files in analysis (default: false, filtered)
IncludeSQLC bool `json:"includeSQLC,omitempty"`
// IncludeTempl includes templ-generated *_templ.go files in analysis (default: false, filtered).
// .templ source files are always included regardless of this setting.
IncludeTempl bool `json:"includeTempl,omitempty"`
// IncludeProtobuf includes protobuf generated files (.pb.go, _grpc.pb.go)
IncludeProtobuf bool `json:"includeProtobuf,omitempty"`
// IncludeMockgen includes mockgen generated files
IncludeMockgen bool `json:"includeMockgen,omitempty"`
// IncludeStringer includes stringer generated files
IncludeStringer bool `json:"includeStringer,omitempty"`
// IncludeGeneric includes files with standard "Code generated by" comments in analysis (default: false, filtered).
// This is a catch-all that catches any tool following the Go convention from https://go.dev/s/generatedcode.
// Includes protoc-gen-connect-go, oapi-codegen, wire, deepcopy-gen, and any other generator.
IncludeGeneric bool `json:"includeGeneric,omitempty"`
// Only restricts analysis to a specific file type (FileTypeGo or FileTypeTempl).
// FileTypeAll (empty string) means analyze all file types.
Only FileType `json:"only,omitempty"`
// IncludePatterns specifies file patterns to always include (takes precedence over filter)
IncludePatterns []string `json:"includePatterns,omitempty"`
// ExcludePatterns specifies additional file patterns to exclude
ExcludePatterns []string `json:"excludePatterns,omitempty"`
// Incremental enables incremental analysis (only analyze changed files)
Incremental bool `json:"incremental,omitempty"`
// Since specifies the git reference for incremental analysis
// Can be a commit hash, branch name, tag, or relative reference (e.g., "HEAD~1")
// If empty and Incremental is true, uses HEAD (all uncommitted changes)
Since string `json:"since,omitempty"`
// CacheDir specifies the cache directory for AST caching
// If empty, uses default .cache/art-dupl
CacheDir string `json:"cacheDir,omitempty"`
// ClearCache clears the cache before running (useful for forced full rebuild)
ClearCache bool `json:"clearCache,omitempty"`
// Semantic enables semantic-aware duplicate detection.
// When true, identifier names are included in the type hash, reducing false positives
// from structurally similar but semantically different code.
//
// Default is true (semantic matching). Use --structural flag to disable
// and match by structure only (more potential matches, more noise).
//
// Example: Expect(x).To(Equal(y)) vs Expect(z).To(Equal(w))
// - Semantic=true (default): Only matches if method names are the same
// - Semantic=false: Matches based on structure only (more potential matches)
Semantic bool `json:"semantic,omitempty"`
// Workers specifies the number of concurrent workers for file parsing.
// 0 or negative means use runtime.GOMAXPROCS(0).
// 1 means sequential processing (same as Parse()).
Workers int `json:"workers,omitempty"`
// DiffMode enables diff visualization for HTML output.
// When enabled, duplicate occurrences are shown with visual diff highlighting.
DiffMode DiffMode `json:"diffMode,omitempty"`
// RichText enables enhanced text output with classification badges,
// priority indicators, and actionable suggestions.
RichText bool `json:"richText,omitempty"`
}
Config represents the dupl configuration with strong typing.
Note: Config uses primitive types (int, string, bool) for JSON marshaling compatibility. Typed enums (FileType, DetectionMethod, etc.) provide validation.
func LoadConfig ¶
LoadConfig loads configuration from file.
func LoadOptionalConfig ¶
LoadOptionalConfig loads configuration from file if filename is not empty. Returns nil if filename is empty, allowing optional config file usage.
func MergeConfigs ¶
MergeConfigs merges two configurations, with command line config taking precedence.
type DetectionConfig ¶
type DetectionConfig struct {
// Methods specifies which detection algorithms to run.
Methods DetectionMethods
// Verbose enables detailed logging during detection.
Verbose bool
}
DetectionConfig holds the subset of configuration needed by the detection layer. This decouples detection from the full Config struct, following the Interface Segregation Principle — detectors only see what they need.
type DetectionMethod ¶
type DetectionMethod string
DetectionMethod represents the detection method type.
const ( // DetectionMethodHash uses hash-based comparison. DetectionMethodHash DetectionMethod = "hash" // DetectionMethodArtDupl uses suffix tree detection. DetectionMethodArtDupl DetectionMethod = "art-dupl" // DetectionMethodTodos finds TODO comments. DetectionMethodTodos DetectionMethod = "todos" // DetectionMethodLegacy finds legacy code patterns. DetectionMethodLegacy DetectionMethod = "legacy" )
func AllDetectionMethods ¶
func AllDetectionMethods() []DetectionMethod
AllDetectionMethods returns all supported detection methods.
func DefaultDetectionMethod ¶
func DefaultDetectionMethod() DetectionMethod
DefaultDetectionMethod returns the default detection method.
func ParseDetectionMethods ¶
func ParseDetectionMethods(methodsStr string) ([]DetectionMethod, error)
ParseDetectionMethods parses comma-separated detection methods.
func (DetectionMethod) IsValid ¶
func (dm DetectionMethod) IsValid() bool
IsValid validates detection method.
func (DetectionMethod) MarshalJSON ¶
func (dm DetectionMethod) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (DetectionMethod) String ¶
func (dm DetectionMethod) String() string
String implements fmt.Stringer.
func (*DetectionMethod) UnmarshalJSON ¶
func (dm *DetectionMethod) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type DetectionMethods ¶
type DetectionMethods []DetectionMethod
DetectionMethods is a slice of DetectionMethod for type safety.
func (DetectionMethods) Contains ¶
func (dm DetectionMethods) Contains(method DetectionMethod) bool
Contains checks if method is in methods list.
func (DetectionMethods) IsDefault ¶
func (dm DetectionMethods) IsDefault() bool
IsDefault checks if methods have default value.
func (DetectionMethods) IsEmpty ¶
func (dm DetectionMethods) IsEmpty() bool
IsEmpty checks if methods list is empty.
func (DetectionMethods) IsHashOnly ¶
func (dm DetectionMethods) IsHashOnly() bool
IsHashOnly checks if only hash detection method is selected. This is useful for optimizing the analysis pipeline - when only hash detection is used, we can skip AST parsing and work directly with file paths.
type DiffMode ¶
type DiffMode string
DiffMode represents the diff visualization mode.
func DefaultDiffMode ¶
func DefaultDiffMode() DiffMode
DefaultDiffMode returns the default diff mode.
func ParseDiffMode ¶
ParseDiffMode parses a diff mode string.
func (DiffMode) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*DiffMode) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type FileType ¶
type FileType string
FileType represents a file type filter for analysis.
func ParseFileType ¶
ParseFileType parses a string into a FileType, validating the value. Returns FileTypeAll and an error if the value is invalid.
func (FileType) MarshalJSON ¶
MarshalJSON implements json.Marshaler. Returns null for empty string to allow omitempty to work.
func (FileType) Matches ¶
Matches returns true if the given file path matches this file type filter. Empty string (FileTypeAll) matches all files.
func (*FileType) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type OutputFormat ¶
type OutputFormat string
OutputFormat represents the output format type.
const ( OutputFormatText OutputFormat = "text" OutputFormatHTML OutputFormat = "html" OutputFormatJSON OutputFormat = "json" OutputFormatCSV OutputFormat = "csv" OutputFormatPlumbing OutputFormat = "plumbing" OutputFormatSimpleJSON OutputFormat = "simple-json" OutputFormatSARIF OutputFormat = "sarif" )
func AllOutputFormats ¶
func AllOutputFormats() []OutputFormat
AllOutputFormats returns all supported output formats.
func DefaultOutputFormat ¶
func DefaultOutputFormat() OutputFormat
DefaultOutputFormat returns the default output format.
func ParseOutputFormat ¶
func ParseOutputFormat(value string) (OutputFormat, error)
ParseOutputFormat converts a string to OutputFormat with validation.
func (OutputFormat) IsValid ¶
func (of OutputFormat) IsValid() bool
IsValid validates output format.
func (OutputFormat) MarshalJSON ¶
func (of OutputFormat) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*OutputFormat) UnmarshalJSON ¶
func (of *OutputFormat) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type SortCriteria ¶
type SortCriteria string
SortCriteria represents the sort criteria type.
const ( SortBySize SortCriteria = "size" SortByOccurrence SortCriteria = "occurrence" SortByHash SortCriteria = "hash" SortByTotalTokens SortCriteria = "total-tokens" )
func AllSortCriteria ¶
func AllSortCriteria() []SortCriteria
AllSortCriteria returns all supported sort criteria.
func DefaultSortCriteria ¶
func DefaultSortCriteria() SortCriteria
DefaultSortCriteria returns the default sort criteria.
func ParseSortCriteria ¶
func ParseSortCriteria(value string) (SortCriteria, error)
ParseSortCriteria converts a string to SortCriteria with validation. Returns an error if the value is not a valid sorting criterion.
func (SortCriteria) IsValid ¶
func (sc SortCriteria) IsValid() bool
IsValid validates sort criteria.
func (SortCriteria) MarshalJSON ¶
func (sc SortCriteria) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*SortCriteria) UnmarshalJSON ¶
func (sc *SortCriteria) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.