config

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2025 License: MIT Imports: 5 Imported by: 0

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 Config

type Config struct {
	Analysis AnalysisConfig `mapstructure:"analysis"`
	Output   OutputConfig   `mapstructure:"output"`
}

Config represents the complete application configuration.

Configuration can be loaded from multiple sources with the following priority (highest to lowest):

  1. CLI flags (set via Merge())
  2. Environment variables (prefixed with CRA_)
  3. Configuration file (YAML format)
  4. 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

func LoadConfig(configPath string) (*Config, error)

LoadConfig loads configuration from multiple sources and merges them.

Configuration is loaded in the following order (later sources override earlier):

  1. Default values (from Default())
  2. Configuration file (YAML format)
  3. 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

func (c *Config) Merge(overrides map[string]interface{})

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"`
}

OutputConfig contains settings that control report formatting and output.

Format determines the output style (currently only "console" is supported). Verbose enables detailed per-file and per-package reporting.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL