Documentation
¶
Overview ¶
Package config handles .htmlvalidate.json configuration file loading.
Index ¶
- Constants
- Variables
- func FindConfigFile(dir string) (string, error)
- func FindIgnoreFile(dir string) (string, error)
- func LoadIgnoreFile(path string) ([]string, error)
- func LoadIgnorePatterns(dir string) ([]string, error)
- func MatchesIgnorePattern(path string, patterns []string) bool
- func ParseSeverity(s string) (rules.Severity, error)
- func ToLinterConfig(fc *FileConfig, configPath string) *linter.Config
- type FileConfig
- type RuleConfig
- type StringOrStrings
Constants ¶
const ConfigFileName = ".htmlvalidate.json"
ConfigFileName is the name of the configuration file.
const IgnoreFileName = ".htmlvalidateignore"
IgnoreFileName is the name of the ignore file.
Variables ¶
var Presets = map[string]*FileConfig{
"html-validate:recommended": recommendedPreset(),
"html-validate:standard": standardPreset(),
"html-validate:a11y": a11yPreset(),
}
Presets contains built-in configuration presets.
Functions ¶
func FindConfigFile ¶
FindConfigFile searches for .htmlvalidate.json from dir upward. Returns empty string if no config file is found.
func FindIgnoreFile ¶
FindIgnoreFile searches for .htmlvalidateignore from dir upward. Returns empty string if no ignore file is found.
func LoadIgnoreFile ¶
LoadIgnoreFile loads patterns from a specific ignore file.
func LoadIgnorePatterns ¶
LoadIgnorePatterns searches for and loads .htmlvalidateignore from dir upward. Returns nil if no ignore file is found.
func MatchesIgnorePattern ¶
MatchesIgnorePattern checks if a path matches any of the ignore patterns. Supports gitignore-style patterns:
- Regular globs: *.html, test_*.go
- Directory patterns (ending with /): node_modules/, vendor/
- Recursive patterns: **/*.generated.html
- Negation: !important.html (not implemented yet)
func ParseSeverity ¶
ParseSeverity converts a severity string to rules.Severity.
func ToLinterConfig ¶
func ToLinterConfig(fc *FileConfig, configPath string) *linter.Config
ToLinterConfig converts a FileConfig to linter.Config.
Types ¶
type FileConfig ¶
type FileConfig struct {
// Root stops parent directory searching when true.
Root bool `json:"root"`
// Extends lists presets or config files to extend.
Extends StringOrStrings `json:"extends"`
// Rules configures individual rule severity.
Rules map[string]RuleConfig `json:"rules"`
}
FileConfig represents the JSON structure of .htmlvalidate.json.
func Load ¶
func Load(dir string) (*FileConfig, string, error)
Load searches for and loads .htmlvalidate.json from dir upward. Returns nil config if no config file is found.
func LoadFile ¶
func LoadFile(path string) (*FileConfig, error)
LoadFile loads a specific configuration file.
type RuleConfig ¶
RuleConfig holds configuration for a single rule. Supports both simple ("error") and array (["error", {}]) formats.
func (*RuleConfig) UnmarshalJSON ¶
func (r *RuleConfig) UnmarshalJSON(data []byte) error
type StringOrStrings ¶
type StringOrStrings []string
StringOrStrings handles JSON that can be either a string or array of strings.
func (*StringOrStrings) UnmarshalJSON ¶
func (s *StringOrStrings) UnmarshalJSON(data []byte) error