config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindConfigDir added in v0.9.0

func FindConfigDir(dir string) string

FindConfigDir walks upward from dir to find the directory containing .ailinter.toml.

func Get

func Get() (string, error)

Get returns a user-friendly representation of the current config.

func IsExcluded added in v0.9.0

func IsExcluded(filePath string, excludePats []string, configDir string) bool

IsExcluded checks if a file path (relative to configDir) matches any exclude pattern. Patterns ending in "/" match directory prefixes; other patterns match exact paths.

func LoadExcludedFiles added in v0.9.0

func LoadExcludedFiles(dir string) []string

LoadExcludedFiles returns the list of excluded file/directory patterns from .ailinter.toml, walking upward from dir. Returns nil if no config or no exclude section.

func LoadProjectThresholds

func LoadProjectThresholds(dir, lang string) parser.Thresholds

LoadProjectThresholds walks from dir upward to find .ailinter.toml, loads the defaults for the language, then merges user overrides.

func Path

func Path() string

Path returns the config file path.

func Save

func Save(c *Config) error

Save writes the configuration to disk.

func Set

func Set(key, value string) (string, error)

Set updates a config value by key and persists.

Types

type Config

type Config struct {
	AccessToken  string         `json:"access_token,omitempty"`
	OnPremURL    string         `json:"onprem_url,omitempty"`
	DefaultPath  string         `json:"default_path,omitempty"`
	EnabledTools []string       `json:"enabled_tools,omitempty"`
	ReadOnly     bool           `json:"read_only,omitempty"`
	Language     string         `json:"language,omitempty"`
	RepoPath     string         `json:"repo_path,omitempty"`
	Thresholds   map[string]int `json:"thresholds,omitempty"`
	DisableGit   bool           `json:"disable_git,omitempty"`
	Project      *ProjectConfig `json:"project,omitempty"`
}

Config represents ailinter's persistent configuration.

func GetConfig

func GetConfig() (*Config, error)

GetConfig returns the current config struct with sensitive fields redacted.

func Load

func Load() (*Config, error)

Load reads the configuration from disk.

func SetAndGet

func SetAndGet(key, value string) (*Config, error)

SetAndGet sets a config value and returns the updated config struct with sensitive fields redacted.

type ExcludeSection added in v0.9.0

type ExcludeSection struct {
	Files []string `toml:"files"`
}

ExcludeSection holds file/directory exclusion patterns.

type ProjectConfig

type ProjectConfig struct {
	Path    string    `json:"path,omitempty"`
	Extends string    `json:"extends,omitempty"`
	Rules   RulesInfo `json:"rules,omitempty"`
}

ProjectConfig holds the project-level .ailinter.toml configuration.

func LoadProjectConfigFile

func LoadProjectConfigFile(cwd string) *ProjectConfig

type RuleBranches

type RuleBranches struct {
	Weight          float64 `toml:"weight"`
	BranchesWarning int     `toml:"branches_warning"`
	BranchesAlert   int     `toml:"branches_alert"`
}

RuleBranches handles complex_conditional thresholds.

type RuleBump

type RuleBump struct {
	Weight       float64 `toml:"weight"`
	BumpsWarning int     `toml:"bumps_warning"`
	BumpDepth    int     `toml:"bump_depth"`
}

RuleBump handles Bumpy Road thresholds.

type RuleFloat

type RuleFloat struct {
	MinLines      int     `toml:"min_lines"`
	MinSimilarity float64 `toml:"min_similarity"`
}

RuleFloat handles thresholds with float/similarity values.

type RuleInt

type RuleInt struct {
	Weight  float64 `toml:"weight"`
	Warning int     `toml:"warning"`
	Alert   int     `toml:"alert"`
}

RuleInt handles thresholds with warning/alert levels.

type RuleLine

type RuleLine struct {
	Warning int     `toml:"warning"`
	Min     int     `toml:"min_lines"`
	Max     int     `toml:"max_consecutive"`
	Ratio   float64 `toml:"ratio"`
}

RuleLine handles thresholds with a single line-count threshold.

type RuleLoc

type RuleLoc struct {
	Weight       float64 `toml:"weight"`
	WarningLines int     `toml:"warning_lines"`
	AlertLines   int     `toml:"alert_lines"`
}

RuleLoc handles thresholds with LOC-based warning_lines/alert_lines.

type RulesInfo

type RulesInfo struct {
	DeepNesting          *int     `json:"deep_nesting_warning,omitempty"`
	BrainMethod          *int     `json:"brain_method_warning_lines,omitempty"`
	FileBloat            *int     `json:"file_bloat_warning_lines,omitempty"`
	CyclomaticComplexity *int     `json:"cyclomatic_complexity_warning,omitempty"`
	BumpyRoad            *int     `json:"bumpy_road_bumps_warning,omitempty"`
	LongParameterList    *int     `json:"long_parameter_list_warning,omitempty"`
	ComplexConditional   *int     `json:"complex_conditional_branches_warning,omitempty"`
	LongSwitch           *int     `json:"long_switch_warning,omitempty"`
	ExcessiveComments    *float64 `json:"excessive_comments_ratio,omitempty"`
}

RulesInfo holds readable rule overrides from .ailinter.toml.

type RulesSection

type RulesSection struct {
	DeepNesting          *RuleInt      `toml:"deep_nesting"`
	BrainMethod          *RuleLoc      `toml:"brain_method"`
	FileBloat            *RuleLoc      `toml:"file_bloat"`
	ComplexConditional   *RuleBranches `toml:"complex_conditional"`
	CyclomaticComplexity *RuleInt      `toml:"cyclomatic_complexity"`
	BumpyRoad            *RuleBump     `toml:"bumpy_road"`
	LongParameterList    *RuleInt      `toml:"long_parameter_list"`
	LazyElement          *RuleLine     `toml:"lazy_element"`
	ParagraphOfCode      *RuleLine     `toml:"paragraph_of_code"`
	MessageChains        *RuleLine     `toml:"message_chains"`
	PrimitiveObsession   *RuleLine     `toml:"primitive_obsession"`
	ExcessiveComments    *RuleLine     `toml:"excessive_comments"`
	GlobalData           *RuleLine     `toml:"global_data"`
	LongScopeVariable    *RuleLine     `toml:"long_scope_variable"`
	DuplicatedCode       *RuleFloat    `toml:"duplicated_code"`
	LongSwitch           *RuleInt      `toml:"long_switch"`
}

RulesSection holds per-detector overrides.

type UserConfig

type UserConfig struct {
	Extends string         `toml:"extends"`
	Rules   RulesSection   `toml:"rules"`
	Exclude ExcludeSection `toml:"exclude"`
}

UserConfig mirrors .ailinter.toml structure.

Jump to

Keyboard shortcuts

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