Documentation
¶
Overview ¶
Package config provides configuration loading and discovery for tally.
Configuration is loaded from multiple sources with the following priority (highest to lowest):
- CLI flags
- Environment variables (TALLY_* prefix)
- Config file (closest .tally.toml or tally.toml)
- Built-in defaults
Config file discovery follows a cascading pattern similar to Ruff: starting from the target file's directory, walk up the filesystem until a config file is found. The closest config wins (no merging).
Index ¶
- Constants
- Variables
- func CIName() string
- func DecodeRuleOptions[T any](rc *RulesConfig, ruleCode string, defaults T) T
- func Discover(targetPath string) string
- func SlowChecksEnabled(mode string) bool
- type AIConfig
- type Config
- type ConfigurationPreference
- type ExcludeConfig
- type FixMode
- type InlineDirectivesConfig
- type OutputConfig
- type RuleConfig
- type RulesConfig
- func (rc *RulesConfig) Get(ruleCode string) *RuleConfig
- func (rc *RulesConfig) GetExcludePaths(ruleCode string) []string
- func (rc *RulesConfig) GetFixMode(ruleCode string) FixMode
- func (rc *RulesConfig) GetOptions(ruleCode string) map[string]any
- func (rc *RulesConfig) GetSeverity(ruleCode string) string
- func (rc *RulesConfig) IsEnabled(ruleCode string) *bool
- func (rc *RulesConfig) Set(ruleCode string, cfg RuleConfig) bool
- type SlowChecksConfig
Constants ¶
const EnvPrefix = "TALLY_"
EnvPrefix is the prefix for environment variables.
Variables ¶
var ConfigFileNames = []string{".tally.toml", "tally.toml"}
ConfigFileNames defines the config file names to search for, in priority order.
Functions ¶
func CIName ¶
func CIName() string
CIName returns the detected CI provider name, or empty string if not in CI.
func DecodeRuleOptions ¶
func DecodeRuleOptions[T any](rc *RulesConfig, ruleCode string, defaults T) T
GetOptionsTyped returns typed rule options merged over defaults. Returns defaults if the rule has no options or decoding fails.
func Discover ¶
Discover finds the closest config file for a target file path. It walks up the directory tree from the target's directory, checking for config files at each level. Returns empty string if no config file is found.
func SlowChecksEnabled ¶
SlowChecksEnabled returns whether slow checks should run based on the mode. "on" → true, "off" → false, "auto" → enabled when not running in CI.
Types ¶
type AIConfig ¶
type AIConfig struct {
// Enabled toggles all AI features in tally. Disabled by default.
Enabled bool `json:"enabled,omitempty" jsonschema:"default=false,description=Enable AI features (opt-in)" koanf:"enabled"`
// Command is the ACP-capable agent program argv (stdio).
// Example: ["acp-agent", "--model", "foo"].
Command []string `json:"command,omitempty" jsonschema:"description=ACP agent command argv (stdio)" koanf:"command"`
// Timeout is the per-fix timeout (e.g. "90s"). Parsed with time.ParseDuration at runtime.
Timeout string `json:"timeout,omitempty" jsonschema:"default=90s,description=Per-fix timeout (e.g. 90s)" koanf:"timeout"`
// MaxInputBytes limits how much content tally will send to the agent (guards cost/latency).
MaxInputBytes int `json:"max-input-bytes,omitempty" jsonschema:"default=262144" koanf:"max-input-bytes"`
// RedactSecrets redacts obvious secrets before sending content to the agent.
RedactSecrets bool `json:"redact-secrets,omitempty" jsonschema:"default=true" koanf:"redact-secrets"`
}
AIConfig configures opt-in AI features.
This is intentionally minimal for MVP. Expand cautiously: AI behavior must remain opt-in.
type Config ¶
type Config struct {
// Rules contains configuration for individual linting rules.
Rules RulesConfig `json:"rules" jsonschema:"description=Rule configuration" koanf:"rules"`
// Output configures output format and destination.
Output OutputConfig `json:"output" jsonschema:"description=Output settings" koanf:"output"`
// InlineDirectives controls inline suppression directives.
InlineDirectives InlineDirectivesConfig `json:"inline-directives" koanf:"inline-directives"`
// AI configures opt-in AI features (e.g., AI AutoFix).
AI AIConfig `json:"ai" koanf:"ai"`
// SlowChecks configures async checks that require network or other slow I/O.
SlowChecks SlowChecksConfig `json:"slow-checks" jsonschema:"description=Slow checks configuration" koanf:"slow-checks"`
// ConfigFile is the path to the config file that was loaded (if any).
// This is metadata, not loaded from config.
ConfigFile string `json:"-" koanf:"-"`
}
Config represents the complete tally configuration.
func Default ¶
func Default() *Config
Default returns the default configuration. Rule-specific defaults are owned by each rule via ConfigurableRule.DefaultConfig().
func Load ¶
Load loads configuration for a target file path. It discovers the closest config file, loads it, and applies environment variable overrides.
func LoadFromFile ¶
LoadFromFile loads configuration from a specific config file path. Unlike Load, it does not perform config discovery.
func LoadWithOverrides ¶
func LoadWithOverrides(targetPath string, overrides map[string]any, preference ConfigurationPreference) (*Config, error)
LoadWithOverrides loads configuration for a target file path with an optional overrides map applied according to preference.
Overrides are expected to use the same (nested) shape as the TOML config file, for example:
overrides := map[string]any{
"output": map[string]any{"format": "json"},
"rules": map[string]any{"include": []any{"tally/*"}},
}
Precedence:
- editorFirst: defaults → filesystem config → env → overrides - filesystemFirst: defaults → overrides → filesystem config → env - editorOnly: defaults → env → overrides (filesystem discovery skipped)
type ConfigurationPreference ¶
type ConfigurationPreference string
ConfigurationPreference controls how editor-provided overrides interact with filesystem config discovery.
This is primarily used by editor integrations (LSP) to decide whether VS Code settings or `.tally.toml` / `tally.toml` should take precedence.
const ( ConfigurationPreferenceEditorFirst ConfigurationPreference = "editorFirst" ConfigurationPreferenceFilesystemFirst ConfigurationPreference = "filesystemFirst" ConfigurationPreferenceEditorOnly ConfigurationPreference = "editorOnly" )
type ExcludeConfig ¶
type ExcludeConfig struct {
// Paths contains glob patterns for files to exclude.
Paths []string `json:"paths,omitempty" jsonschema:"description=Glob patterns for files to exclude (e.g. test/**)" koanf:"paths"`
}
ExcludeConfig defines file exclusion patterns for a rule.
type FixMode ¶
type FixMode string
FixMode controls when auto-fixes are applied for a rule.
const ( // FixModeNever disables fixes even with --fix. FixModeNever FixMode = "never" // FixModeExplicit requires --fix-rule to apply. FixModeExplicit FixMode = "explicit" // FixModeAlways applies with --fix when safety threshold is met (default). FixModeAlways FixMode = "always" // FixModeUnsafeOnly requires --fix-unsafe to apply. FixModeUnsafeOnly FixMode = "unsafe-only" )
type InlineDirectivesConfig ¶
type InlineDirectivesConfig struct {
// Enabled controls whether inline directives are processed.
Enabled bool `json:"enabled,omitempty" jsonschema:"default=true,description=Process inline ignore directives" koanf:"enabled"`
// WarnUnused reports warnings for directives that don't suppress any violations.
WarnUnused bool `json:"warn-unused,omitempty" jsonschema:"default=false,description=Warn about unused directives" koanf:"warn-unused"`
// ValidateRules reports warnings for unknown rule codes in directives.
ValidateRules bool `json:"validate-rules,omitempty" jsonschema:"default=false" koanf:"validate-rules"`
// RequireReason reports warnings for directives without a reason= explanation.
RequireReason bool `json:"require-reason,omitempty" jsonschema:"default=false" koanf:"require-reason"`
}
InlineDirectivesConfig controls inline suppression directives. Supports # tally ignore=..., # hadolint ignore=..., and # check=skip=...
Example TOML configuration:
[inline-directives] enabled = true warn-unused = false validate-rules = true require-reason = false
type OutputConfig ¶
type OutputConfig struct {
// Format specifies the output format.
Format string `json:"format,omitempty" koanf:"format"`
// Path specifies where to write output.
Path string `json:"path,omitempty" koanf:"path"`
// ShowSource enables source code snippets in text output.
ShowSource bool `json:"show-source,omitempty" koanf:"show-source"`
// FailLevel sets the minimum severity level that causes a non-zero exit code.
FailLevel string `json:"fail-level,omitempty" koanf:"fail-level"`
}
OutputConfig configures output formatting and behavior.
type RuleConfig ¶
type RuleConfig struct {
// Severity overrides the rule's default severity.
// Use "off" to disable the rule.
Severity string `json:"severity,omitempty" jsonschema:"enum=off,enum=error,enum=warning,enum=info,enum=style" koanf:"severity"`
// Fix controls when auto-fixes are applied for this rule.
// Values: never, explicit, always (default), unsafe-only.
Fix FixMode `json:"fix,omitempty" jsonschema:"enum=never,enum=explicit,enum=always,enum=unsafe-only" koanf:"fix"`
// Exclude contains path patterns where this rule should not run.
Exclude ExcludeConfig `json:"exclude" koanf:"exclude"`
// Options contains rule-specific configuration options.
Options map[string]any `json:"-" koanf:",remain"`
}
RuleConfig represents per-rule configuration. Can be specified in TOML as:
[rules.tally.max-lines] severity = "warning" fix = "always" # Rule-specific options are flattened at this level max = 100 skip-blank-lines = true
type RulesConfig ¶
type RulesConfig struct {
// Include explicitly enables rules.
Include []string `json:"include,omitempty" jsonschema:"description=Enable rules by pattern (e.g. buildkit/*)" koanf:"include"`
// Exclude explicitly disables rules.
Exclude []string `json:"exclude,omitempty" jsonschema:"description=Disable rules by pattern" koanf:"exclude"`
// Tally contains configuration for tally/* rules.
Tally map[string]RuleConfig `json:"tally,omitempty" jsonschema:"description=Configuration for tally/* rules" koanf:"tally"`
// Buildkit contains configuration for buildkit/* rules.
Buildkit map[string]RuleConfig `json:"buildkit,omitempty" jsonschema:"description=Configuration for buildkit/* rules" koanf:"buildkit"`
// Hadolint contains configuration for hadolint/* rules.
Hadolint map[string]RuleConfig `json:"hadolint,omitempty" jsonschema:"description=Configuration for hadolint/* rules" koanf:"hadolint"`
}
RulesConfig contains rule selection and per-rule configuration.
Example TOML (Ruff-style selection):
[rules] include = ["buildkit/*"] # Enable all buildkit rules exclude = ["buildkit/MaintainerDeprecated"] # Disable specific rules [rules.tally.max-lines] severity = "warning" max = 100 [rules.hadolint.DL3026] severity = "warning" trusted-registries = ["docker.io", "gcr.io"]
func (*RulesConfig) Get ¶
func (rc *RulesConfig) Get(ruleCode string) *RuleConfig
Get returns the configuration for a specific rule. Returns nil if no configuration exists for the rule. ruleCode should be namespaced (e.g., "buildkit/StageNameCasing").
func (*RulesConfig) GetExcludePaths ¶
func (rc *RulesConfig) GetExcludePaths(ruleCode string) []string
GetExcludePaths returns the exclusion patterns for a rule.
func (*RulesConfig) GetFixMode ¶
func (rc *RulesConfig) GetFixMode(ruleCode string) FixMode
GetFixMode returns the fix mode for a rule. Returns FixModeAlways (default) if no override is configured.
func (*RulesConfig) GetOptions ¶
func (rc *RulesConfig) GetOptions(ruleCode string) map[string]any
GetOptions returns rule-specific options. Returns nil if no options are configured. Returns a shallow copy to prevent mutation of internal state.
func (*RulesConfig) GetSeverity ¶
func (rc *RulesConfig) GetSeverity(ruleCode string) string
GetSeverity returns the severity override for a rule. Returns empty string if no override is configured.
func (*RulesConfig) IsEnabled ¶
func (rc *RulesConfig) IsEnabled(ruleCode string) *bool
IsEnabled checks if a rule is enabled based on Include/Exclude patterns. Returns nil if no configuration specifies enabled/disabled (use rule default). Include takes precedence over Exclude (Ruff-style semantics).
func (*RulesConfig) Set ¶
func (rc *RulesConfig) Set(ruleCode string, cfg RuleConfig) bool
Set stores configuration for a rule. Creates the namespace map if nil. Returns false if the namespace is unknown.
type SlowChecksConfig ¶
type SlowChecksConfig struct {
// Mode controls when slow checks run: auto (CI detection), on, off.
Mode string `json:"mode,omitempty" jsonschema:"default=auto,enum=auto,enum=on,enum=off,description=When to run slow checks" koanf:"mode"`
// FailFast skips async checks when fast checks already produce SeverityError violations.
FailFast bool `json:"fail-fast,omitempty" jsonschema:"default=true,description=Skip slow checks when errors found" koanf:"fail-fast"`
// Timeout is the wall-clock budget for all async checks per invocation.
Timeout string `json:"timeout,omitempty" jsonschema:"default=20s,description=Timeout for slow checks (e.g. 20s)" koanf:"timeout"`
}
SlowChecksConfig configures async checks that require potentially slow I/O (registry access, network, filesystem).
Example TOML configuration:
[slow-checks] mode = "auto" fail-fast = true timeout = "20s"