Documentation
¶
Overview ¶
Package templint provides a static linter for .templ files.
It checks for common issues such as inline control flow (which templ silently drops), missing accessibility attributes, and style anti-patterns.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllRuleIDs ¶
func AllRuleIDs() []string
AllRuleIDs returns the sorted IDs of every rule registered with the linter.
func HasErrors ¶
func HasErrors(diags []Diagnostic) bool
HasErrors returns true if any diagnostic has Error severity.
Types ¶
type Config ¶
Config holds the linter configuration. Rules maps a rule ID to the severity it should report at; rules not present in the map are disabled.
func LoadConfig ¶
LoadConfig reads a hamr.toml file and returns the parsed [lint.templ] Config. Returns nil if the file does not exist or the section is empty.
Each entry is a rule ID mapped to one of "warning", "error", or "off". An entry of "off" is equivalent to omitting the rule. Unknown rule IDs and invalid severities are returned as errors.
type Diagnostic ¶
type Diagnostic struct {
File string
Line int
Col int
Rule string
Severity Severity
Message string
}
Diagnostic represents a single lint finding.
func FilterBySeverity ¶
func FilterBySeverity(diags []Diagnostic, minSev Severity) []Diagnostic
FilterBySeverity returns only diagnostics at or above the given severity.
func (Diagnostic) String ¶
func (d Diagnostic) String() string
String returns a formatted diagnostic string.
type Linter ¶
type Linter struct {
// contains filtered or unexported fields
}
Linter applies rules to .templ files and collects diagnostics.
func New ¶
New creates a Linter configured by the given Config. Only rules listed in cfg.Rules are enabled; passing nil or an empty Config yields a linter that reports nothing.
func (*Linter) LintDir ¶
func (l *Linter) LintDir(dir string) ([]Diagnostic, error)
LintDir walks a directory tree and lints all .templ files.
type Rule ¶
type Rule interface {
ID() string
Check(filename string, lines []string) []Diagnostic
}
Rule is the interface that all lint rules must implement.
type Severity ¶
type Severity int
Severity indicates the severity level of a diagnostic.
func DefaultSeverity ¶
DefaultSeverity returns the recommended default severity for a rule, used when callers need to enable a rule without an explicit severity (e.g. the --rule CLI flag). Returns Warning for unknown rule IDs.
func ParseSeverity ¶
ParseSeverity converts a string to a Severity.