config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Filenames = []string{"krit.yml", ".krit.yml"}

Filenames lists the krit configuration filenames, in the order callers should probe for them. Centralised so adding a third name (e.g. krit.yaml) is a one-line change.

Functions

func FindDefaultConfig

func FindDefaultConfig() string

FindDefaultConfig locates the default config file. It checks relative to the executable path first, then the current directory.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config holds the parsed YAML configuration for krit rules. The data structure is: ruleSet -> ruleName -> key -> value

func LoadAndMerge

func LoadAndMerge(userPath string, defaultPath string) (*Config, error)

LoadAndMerge loads defaults first, then merges user config on top. If userPath is empty, auto-detection is used for the user config. If no user config is found, defaults alone are returned.

func LoadConfig

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

LoadConfig loads a YAML config file and returns a Config. If path is empty, it auto-detects krit.yml or .krit.yml from the project root, falling back to config/default-krit.yml relative to the executable.

func NewConfig

func NewConfig() *Config

NewConfig creates an empty Config.

func (*Config) Data

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

Data returns the underlying config data map for serialization (e.g., cache hashing).

func (*Config) GetBool

func (c *Config) GetBool(ruleSet, rule, key string, defaultVal bool) bool

GetBool returns a bool config value for a rule, or defaultVal if not found.

func (*Config) GetInt

func (c *Config) GetInt(ruleSet, rule, key string, defaultVal int) int

GetInt returns an integer config value for a rule, or defaultVal if not found.

func (*Config) GetString

func (c *Config) GetString(ruleSet, rule, key string, defaultVal string) string

GetString returns a string config value for a rule, or defaultVal if not found.

func (*Config) GetStringList

func (c *Config) GetStringList(ruleSet, rule, key string) []string

GetStringList returns a string slice config value for a rule. Returns nil if not found.

func (*Config) GetTopLevelBool

func (c *Config) GetTopLevelBool(key string, defaultVal bool) bool

GetTopLevelBool returns a bool value from a top-level config key. For example, GetTopLevelBool("warningsAsErrors", false) reads config.warningsAsErrors.

func (*Config) GetTopLevelInt

func (c *Config) GetTopLevelInt(section, key string, defaultVal int) int

GetTopLevelInt returns an int value nested under a top-level section. For example, GetTopLevelInt("parseCache", "maxSizeMB", 200) reads parseCache.maxSizeMB.

func (*Config) GetTopLevelList

func (c *Config) GetTopLevelList(key string) []string

func (*Config) GetTopLevelString

func (c *Config) GetTopLevelString(section, key, defaultVal string) string

GetTopLevelString returns a string value from a top-level config section. For example, GetTopLevelString("android", "enabled", "auto") reads android.enabled.

func (*Config) GetTopLevelStringList

func (c *Config) GetTopLevelStringList(section, key string) []string

GetTopLevelStringList returns a string slice from a top-level section.

func (*Config) Has

func (c *Config) Has(ruleSet, rule, key string) bool

Has reports whether a given rule config key is set in the YAML (i.e. the key exists under ruleSet.rule in the config map). Used by the registry- driven ApplyConfig path to distinguish "key absent" from "key set to the zero value" — GetInt/GetString/GetBool all return the default when the key is missing, which is the same shape they return when a legitimate override happens to equal the default. HasKey on ConfigSource is the contract that lets descriptor Apply closures know whether to mutate the rule struct.

func (*Config) IsRuleActive

func (c *Config) IsRuleActive(ruleSet, rule string) *bool

IsRuleActive returns whether a rule is active in the config. Returns nil if the rule is not mentioned in config (caller should use default).

func (*Config) IsRuleSetActive

func (c *Config) IsRuleSetActive(ruleSet string) *bool

IsRuleSetActive returns whether an entire ruleset is active. Returns nil if not specified.

func (*Config) ModuleTemplate

func (c *Config) ModuleTemplate() ModuleTemplateConfig

ModuleTemplate returns the configured feature-module template, if any.

func (*Config) SLOs

func (c *Config) SLOs() []SLOConfig

func (*Config) Set

func (c *Config) Set(ruleSet, rule, key string, value interface{})

Set writes a value into the config for a specific rule.

func (*Config) TestSourcePaths

func (c *Config) TestSourcePaths() []string

func (*Config) TestSourcePathsOverride

func (c *Config) TestSourcePathsOverride() []string

type EditorConfig

type EditorConfig struct {
	MaxLineLength          int    // max_line_length (0 = not set, -1 = off)
	IndentSize             int    // indent_size (0 = not set)
	TabWidth               int    // tab_width (0 = not set)
	IndentStyle            string // "space" or "tab" or ""
	Charset                string // charset or ""
	InsertFinalNewline     *bool  // insert_final_newline (nil = not set)
	TrimTrailingWhitespace *bool  // trim_trailing_whitespace (nil = not set)
}

EditorConfig holds parsed .editorconfig properties relevant to krit. Only reads standard properties that affect analysis rules. Does NOT read ktlint_*, ij_kotlin_*, or ktfmt_* properties.

func LoadEditorConfig

func LoadEditorConfig(startPath string) *EditorConfig

LoadEditorConfig walks up the directory tree from startPath looking for .editorconfig files. Merges properties from all found files (closest wins). Stops at a file with root = true.

func (*EditorConfig) ApplyToConfig

func (ec *EditorConfig) ApplyToConfig(cfg *Config)

ApplyEditorConfigToRules updates rule configuration based on .editorconfig values. Called after YAML config is loaded — .editorconfig values override YAML for the properties it covers (matching ktfmt's behavior).

type ModuleTemplateConfig

type ModuleTemplateConfig struct {
	FeatureRoot        string
	RequiredSubmodules []string
	RequiredPlugins    []string
}

ModuleTemplateConfig describes the optional top-level module_template block.

type SLOConfig

type SLOConfig struct {
	Module             string
	MaxWarningsPerKLOC *float64
	MaxErrorsPerKLOC   *float64
}

Jump to

Keyboard shortcuts

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