config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config handles .htmlvalidate.json configuration file loading.

Index

Constants

View Source
const ConfigFileName = ".htmlvalidate.json"

ConfigFileName is the name of the configuration file.

View Source
const IgnoreFileName = ".htmlvalidateignore"

IgnoreFileName is the name of the ignore file.

Variables

View Source
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

func FindConfigFile(dir string) (string, error)

FindConfigFile searches for .htmlvalidate.json from dir upward. Returns empty string if no config file is found.

func FindIgnoreFile

func FindIgnoreFile(dir string) (string, error)

FindIgnoreFile searches for .htmlvalidateignore from dir upward. Returns empty string if no ignore file is found.

func LoadIgnoreFile

func LoadIgnoreFile(path string) ([]string, error)

LoadIgnoreFile loads patterns from a specific ignore file.

func LoadIgnorePatterns

func LoadIgnorePatterns(dir string) ([]string, error)

LoadIgnorePatterns searches for and loads .htmlvalidateignore from dir upward. Returns nil if no ignore file is found.

func MatchesIgnorePattern

func MatchesIgnorePattern(path string, patterns []string) bool

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

func ParseSeverity(s string) (rules.Severity, error)

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.

func Resolve

func Resolve(dir string) (*FileConfig, string, error)

Resolve loads a config and resolves all extends.

type RuleConfig

type RuleConfig struct {
	Severity string
	Options  map[string]any
}

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

Jump to

Keyboard shortcuts

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