Documentation
¶
Overview ¶
Package config handles configuration management for the code review assistant.
Configuration is loaded with the following priority (highest to lowest): 1. CLI flags (passed via command-line arguments) 2. Environment variables 3. Configuration file (YAML format) 4. Default values
Configuration File ¶
The configuration file uses YAML format and supports the following sections:
analysis: large_file_threshold: 500 long_function_threshold: 50 complexity_threshold: 10 max_parameters: 5 enable_coverage: true min_coverage_threshold: 50.0 output: format: console verbose: false
Usage ¶
Load configuration from file:
cfg, err := config.LoadConfig("config.yaml")
if err != nil {
log.Fatal(err)
}
Apply CLI flag overrides:
overrides := map[string]interface{}{
"complexity_threshold": 15,
"verbose": true,
}
cfg.Merge(overrides)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnalysisConfig ¶
type AnalysisConfig struct {
ExcludePatterns []string `mapstructure:"exclude_patterns"`
LargeFileThreshold int `mapstructure:"large_file_threshold"`
LongFunctionThreshold int `mapstructure:"long_function_threshold"`
MinCommentRatio float64 `mapstructure:"min_comment_ratio"`
ComplexityThreshold int `mapstructure:"complexity_threshold"`
// Anti-pattern detection
MaxParameters int `mapstructure:"max_parameters"`
MaxNestingDepth int `mapstructure:"max_nesting_depth"`
MaxReturnStatements int `mapstructure:"max_return_statements"`
DetectMagicNumbers bool `mapstructure:"detect_magic_numbers"`
DetectDuplicateErrors bool `mapstructure:"detect_duplicate_errors"`
// Test coverage
EnableCoverage bool `mapstructure:"enable_coverage"`
MinCoverageThreshold float64 `mapstructure:"min_coverage_threshold"`
CoverageTimeout int `mapstructure:"coverage_timeout_seconds"`
// Dependency analysis
MaxImports int `mapstructure:"max_imports"`
MaxExternalDependencies int `mapstructure:"max_external_dependencies"`
DetectCircularDeps bool `mapstructure:"detect_circular_deps"`
}
AnalysisConfig contains all settings that control code analysis behavior.
This includes:
- File and function size thresholds
- Complexity thresholds
- Anti-pattern detection settings
- Test coverage configuration
- Dependency analysis settings
All threshold values can be overridden via CLI flags, environment variables, or configuration files.
type ComparisonConfig ¶ added in v0.3.0
type ComparisonConfig struct {
Enabled bool `mapstructure:"enabled"` // Enable comparison
AutoCompare bool `mapstructure:"auto_compare"` // Auto-compare with latest
StableThreshold float64 `mapstructure:"stable_threshold"` // % change for "stable" (default: 5.0)
}
ComparisonConfig contains settings for historical comparison.
Phase 3: Enables comparison with previous analysis runs.
type Config ¶
type Config struct {
Analysis AnalysisConfig `mapstructure:"analysis"`
Output OutputConfig `mapstructure:"output"`
Storage StorageConfig `mapstructure:"storage"` // Phase 3: Persistent storage
Comparison ComparisonConfig `mapstructure:"comparison"` // Phase 3: Historical comparison
}
Config represents the complete application configuration.
Configuration can be loaded from multiple sources with the following priority (highest to lowest):
- CLI flags (set via Merge())
- Environment variables (prefixed with CRA_)
- Configuration file (YAML format)
- Default values (from Default())
This layered approach allows flexible configuration for different environments while maintaining sensible defaults.
func Default ¶
func Default() *Config
Default returns a Config with sensible default values for all settings.
These defaults are based on industry best practices and common code quality standards:
- Large file threshold: 500 lines
- Long function threshold: 50 lines
- Cyclomatic complexity threshold: 10
- Minimum comment ratio: 15%
- Test coverage threshold: 50%
All anti-pattern detectors are enabled by default. Files matching common patterns (vendor/, testdata/, *_test.go, *.pb.go) are excluded from analysis.
func LoadConfig ¶
LoadConfig loads configuration from multiple sources and merges them.
Configuration is loaded in the following order (later sources override earlier):
- Default values (from Default())
- Configuration file (YAML format)
- Environment variables (prefixed with CRA_)
Configuration File Search: If configPath is provided, only that file is loaded. Otherwise, the loader searches for "config.yaml" in:
- Current directory
- User's home directory (~/.cra/)
Environment Variables: All settings can be overridden via environment variables with the CRA_ prefix. For example: CRA_ANALYSIS_COMPLEXITY_THRESHOLD=15
Returns the merged configuration or an error if the config file exists but cannot be read. Missing config files are acceptable and will use defaults.
func (*Config) Merge ¶
Merge merges CLI flag overrides into the configuration.
This method applies command-line flag overrides with the highest priority, allowing users to override config file and environment settings on a per-invocation basis.
The overrides map should contain flag names as keys and their values. Only non-zero/non-empty values are applied to avoid overwriting valid config with flag defaults.
Example:
overrides := map[string]interface{}{
"complexity_threshold": 15,
"verbose": true,
}
config.Merge(overrides)
type OutputConfig ¶
type OutputConfig struct {
Format string `mapstructure:"format"`
Verbose bool `mapstructure:"verbose"`
OutputFile string `mapstructure:"output_file"` // Phase 3: File output path
JSONPretty bool `mapstructure:"json_pretty"` // Phase 3: Pretty-print JSON
QuietMode bool `mapstructure:"quiet"` // Disable live status reporting
ShowStatus bool `mapstructure:"show_status"` // Force enable status reporting
}
OutputConfig contains settings that control report formatting and output.
Format determines the output style: console, markdown, json. Verbose enables detailed per-file and per-package reporting. OutputFile specifies a file path for output (empty means stdout). JSONPretty controls JSON formatting (pretty vs compact). QuietMode disables live status reporting. ShowStatus forces status reporting even when output is piped.
type StorageConfig ¶ added in v0.3.0
type StorageConfig struct {
Enabled bool `mapstructure:"enabled"` // Enable storage
Backend string `mapstructure:"backend"` // "file" or "sqlite"
Path string `mapstructure:"path"` // Custom storage path (empty = default)
AutoSave bool `mapstructure:"auto_save"` // Automatically save after analysis
ProjectMode bool `mapstructure:"project_mode"` // Use ./.cra instead of ~/.cra
}
StorageConfig contains settings for persistent storage of analysis reports.
Phase 3: Enables saving reports for historical tracking and comparison.