Documentation
¶
Index ¶
- Variables
- func ApplyCategories(rules map[string]RuleCfg, categories map[string]bool, ...) map[string]RuleCfg
- func Discover(startDir string) (string, error)
- func Effective(cfg *Config, filePath string) map[string]RuleCfg
- func EffectiveCategories(cfg *Config, filePath string) map[string]bool
- func EffectiveExplicitRules(cfg *Config, filePath string) map[string]bool
- func IsIgnored(patterns []string, path string) bool
- type Config
- type Override
- type RuleCfg
Constants ¶
This section is empty.
Variables ¶
var DefaultFiles = []string{"**/*.md", "**/*.markdown"}
DefaultFiles is the built-in list of glob patterns used for file discovery when no file arguments are given on the command line.
var ValidCategories = []string{
"heading",
"whitespace",
"code",
"list",
"line",
"link",
"meta",
"table",
}
ValidCategories lists the recognized rule category names.
Functions ¶
func ApplyCategories ¶
func ApplyCategories( rules map[string]RuleCfg, categories map[string]bool, ruleCategory func(ruleName string) string, explicit map[string]bool, ) map[string]RuleCfg
ApplyCategories disables rules whose category is disabled, unless the rule has been explicitly configured (present in the explicit rules map). ruleCategory maps a rule name to its category string. The explicit map contains rule names that were explicitly set in config (not just inherited from defaults).
func Discover ¶
Discover walks up the directory tree from startDir looking for a .mdsmith.yml config file. It stops searching when it encounters a .git directory (the repository root) or reaches the filesystem root. Returns the path to the config file, or "" if none was found.
func Effective ¶
Effective returns the effective rule configuration for a given file path. It starts with the top-level rules and then applies each override whose file patterns match filePath, in order. Later overrides take precedence.
func EffectiveCategories ¶
EffectiveCategories returns the effective category settings for a given file path. It starts with the top-level categories and then applies each override whose file patterns match filePath, in order. Categories not explicitly set default to true (enabled).
func EffectiveExplicitRules ¶
EffectiveExplicitRules returns the set of rule names that were explicitly configured for a given file path. It includes rules from the top-level ExplicitRules and any rules set by matching overrides.
Types ¶
type Config ¶
type Config struct {
Rules map[string]RuleCfg `yaml:"rules"`
Ignore []string `yaml:"ignore"`
Overrides []Override `yaml:"overrides"`
FrontMatter *bool `yaml:"front-matter"`
Categories map[string]bool `yaml:"categories"`
Files []string `yaml:"files"`
NoFollowSymlinks []string `yaml:"no-follow-symlinks"`
// ExplicitRules tracks rule names that were explicitly set in
// the user config (not just inherited from defaults). This is
// used for category override resolution: an explicitly enabled
// rule takes precedence over a disabled category.
// Not serialized to YAML.
ExplicitRules map[string]bool `yaml:"-"`
// FilesExplicit tracks whether the files key was explicitly set
// in the user config. This distinguishes between an omitted key
// (use defaults) and an explicitly empty list (no files).
// Not serialized to YAML.
FilesExplicit bool `yaml:"-"`
}
Config is the top-level configuration.
func Defaults ¶
func Defaults() *Config
Defaults returns a Config with all registered rules using each rule's default enabled state and no custom settings.
func DumpDefaults ¶
func DumpDefaults() *Config
DumpDefaults returns a Config with all registered rules using each rule's default enabled state. Enabled rules that implement Configurable have their DefaultSettings() included in RuleCfg.Settings. Categories are included with all set to true (enabled). This is consumed by `mdsmith init` to generate a default config file.
func Merge ¶
Merge merges a loaded config on top of defaults. The loaded config's rules override the defaults; any rule not mentioned in loaded keeps its default value. Ignore and Overrides come from the loaded config only. Categories from the loaded config are merged on top of defaults; any category not mentioned in loaded keeps its default value (true).
type Override ¶
type Override struct {
Files []string `yaml:"files"`
Rules map[string]RuleCfg `yaml:"rules"`
Categories map[string]bool `yaml:"categories"`
}
Override applies rule settings to files matching glob patterns.
type RuleCfg ¶
RuleCfg is a YAML union: can be bool (enable/disable) or map[string]any (settings).
func (RuleCfg) MarshalYAML ¶
MarshalYAML implements custom YAML marshalling for RuleCfg. A disabled rule (Enabled=false, no Settings) serializes as `false`. An enabled rule with settings serializes as the settings mapping. An enabled rule with no settings serializes as `true`.
func (*RuleCfg) UnmarshalYAML ¶
UnmarshalYAML implements custom YAML unmarshalling for RuleCfg. It handles three forms:
- false -> Enabled=false, Settings=nil
- true -> Enabled=true, Settings=nil
- {key: val, ...} -> Enabled=true, Settings={key: val, ...}