Documentation
¶
Overview ¶
Package config loads and validates Clover's optional YAML configuration. Two layers share one shape and one embedded JSON schema: a user config under the XDG config dir, and a per-project .clover.yaml that overlays it. The schema is also published for editor tooling.
Settings are grouped by the command they configure (run/lint/fmt), with a global block for cross-command defaults like output detail; per-command keys override the global one, and an explicit CLI flag overrides both.
Index ¶
- func CommonExcludes() []string
- func DefaultExcludes() []string
- func Starter(requiredVersion string, excludes []string) []byte
- type Config
- func (c *Config) CheckVersion(current string) error
- func (c *Config) Deep() *bool
- func (c *Config) Downgrade() *bool
- func (c *Config) ExcludeGlobs() []string
- func (c *Config) Force() *bool
- func (c *Config) LintOutput(cli *output.Mode) output.Mode
- func (c *Config) Prerelease() *bool
- func (c *Config) Prune() *bool
- func (c *Config) RunOutput(cli *output.Mode) output.Mode
- func (c *Config) Verify() *bool
- type Format
- type Global
- type Lint
- type Paths
- type Resolver
- type Run
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommonExcludes ¶
func CommonExcludes() []string
CommonExcludes returns the exclude globs the init wizard offers, as a fresh copy.
func DefaultExcludes ¶
func DefaultExcludes() []string
DefaultExcludes returns the exclude globs preselected by the init wizard, as a fresh copy.
func Starter ¶
Starter renders a commented starter .clover.yaml. A non-empty requiredVersion becomes an active required-version constraint; an empty one is shown as a commented example, documenting the field without imposing a gate. Likewise a non-empty excludes becomes an active paths.exclude block; an empty one is shown commented, so the output never carries a null array. The output carries a yaml-language-server modeline so editors validate it against the published schema, and round-trips cleanly through Load.
Types ¶
type Config ¶
type Config struct {
RequiredVersion *string `yaml:"required-version"`
Paths Paths `yaml:"paths"`
Global Global `yaml:"global"`
Run Run `yaml:"run"`
Lint Lint `yaml:"lint"`
Format Format `yaml:"fmt"`
}
Config is a parsed .clover.yaml. Pointer fields are tri-state: nil means the key was absent (so a lower-precedence layer or built-in default applies), distinct from an explicit false/zero that overrides it.
func Load ¶
Load reads the project config from path, or - when path is empty - the first of .clover.yaml/.clover.yml found in dir, validating it against the embedded schema. It returns nil with no error when no file is found and none was requested, so an absent config is simply no config.
func LoadUser ¶
LoadUser reads the user config from <config-dir>/clover/config.yaml (or .yml), where <config-dir> is $XDG_CONFIG_HOME or its per-OS default (e.g. ~/.config). Like Load it returns nil with no error when no file is present. Its settings form the base that a project config overlays via Merge.
func Merge ¶
Merge returns the effective config: the user config overlaid by the project one, field by field. The project layer always takes precedence - any field it sets wins, and only the fields it leaves unset fall back to user. Either argument may be nil. Configs are treated as immutable after load: the result is a fresh top-level value, but its pointer and slice leaves may alias an input's, so callers must not mutate them in place.
func (*Config) CheckVersion ¶
CheckVersion verifies the running clover version satisfies required-version. An empty constraint, or a current version that does not parse (a dev build), passes - the gate never blocks an unversioned binary.
func (*Config) ExcludeGlobs ¶
ExcludeGlobs returns the configured exclude globs, nil-safe so callers need not branch on a missing config.
func (*Config) Force ¶
Force returns the configured run.force default (nil = unset). When true, a followed digest is re-pinned even if the version it follows is unchanged.
func (*Config) LintOutput ¶
LintOutput resolves the output detail for `clover lint`, with the same precedence as Config.RunOutput but keyed on lint.output.
func (*Config) Prerelease ¶
Prerelease returns the configured run.prerelease default (nil = unset).
func (*Config) RunOutput ¶
RunOutput resolves the output detail for `clover run`: the CLI value when set, then run.output, then global.output, then the built-in text default.
func (*Config) Verify ¶
Verify, Prerelease, Downgrade, and Deep return the configured run defaults as tri-state pointers (nil = unset), nil-safe on the config. A caller resolves the effective value as cmp.Or(cliFlag, cfg.Verify()): the CLI flag wins, then the config, then the per-marker directive that a nil leaves untouched.
type Format ¶
type Format struct {
Prune *bool `yaml:"prune"`
}
Format holds defaults for `clover fmt`.
type Paths ¶
type Paths struct {
Exclude []string `yaml:"exclude"`
}
Paths controls which files clover scans.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver resolves the effective config governing a scanned path: the user config overlaid by the project .clover.yaml at the path's repository root (or, when the path is not in a repository, its own directory). Each root's config is loaded and merged once, then memoized, so a scan spanning many files across a handful of repositories does only a handful of reads. It also records the distinct roots it resolves, so a caller can tell a single-repository scan from a multi-repository one. Safe for concurrent use.
Two flags short-circuit discovery: an explicit --config governs every path, and --no-config yields nil for all of them.
func NewResolver ¶
NewResolver builds a per-root config resolver. user is the loaded user (XDG) config and may be nil. explicit is the --config path: when non-empty it is loaded for every path and root discovery is skipped. noConfig, the --no-config flag, makes every lookup nil for a fully unconfigured run.
func (*Resolver) Err ¶
Err returns the first project-config load error the resolver encountered while resolving paths, or nil. A malformed config is a hard error a caller surfaces after the scan, even when every file under the bad root was excluded or carried no directive.
func (*Resolver) ForDir ¶
ForDir returns the effective config governing the directory dir: the project config at dir's repository root (or dir itself when not in a repository), overlaid on the user config and memoized per root. With --config the explicit file governs every directory; with --no-config it returns nil. A malformed project config surfaces its load error (memoized, so it is read once).
func (*Resolver) Primary ¶
Primary returns the config to resolve per-invocation settings (output detail, fmt.prune) from: the explicit --config when set; else the sole root's config when the scan resolved to exactly one repository, so a single-tree run still honours its project config; else the user config, so a multi-repository scan falls back to the user default. It is meaningful only after the scan has driven ForDir over the scanned tree.