Documentation
¶
Index ¶
- type CategoryConfig
- type Config
- type ConfigurableRule
- type CustomRulesConfig
- type DocGenerator
- func (g *DocGenerator[T]) GenerateAllRuleDocs() []*RuleDoc
- func (g *DocGenerator[T]) GenerateCategoryDocs() map[string][]*RuleDoc
- func (g *DocGenerator[T]) GenerateRuleDoc(rule RuleRunner[T]) *RuleDoc
- func (g *DocGenerator[T]) WriteJSON(w io.Writer) error
- func (g *DocGenerator[T]) WriteMarkdown(w io.Writer) error
- type DocumentInfo
- type DocumentedRule
- type LintOptions
- type Linter
- type Output
- type OutputFormat
- type Registry
- func (r *Registry[T]) AllCategories() []string
- func (r *Registry[T]) AllRuleIDs() []string
- func (r *Registry[T]) AllRules() []RuleRunner[T]
- func (r *Registry[T]) AllRulesets() []string
- func (r *Registry[T]) GetRule(id string) (RuleRunner[T], bool)
- func (r *Registry[T]) GetRuleset(name string) ([]string, bool)
- func (r *Registry[T]) Register(rule RuleRunner[T])
- func (r *Registry[T]) RegisterRuleset(name string, ruleIDs []string) error
- func (r *Registry[T]) RulesetsContaining(ruleID string) []string
- type Rule
- type RuleConfig
- type RuleDoc
- type RuleEntry
- type RuleRunner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CategoryConfig ¶
type CategoryConfig struct {
// Enabled controls whether all rules in the category are active
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
// Severity overrides the default severity for all rules in the category
Severity *validation.Severity `yaml:"severity,omitempty" json:"severity,omitempty"`
}
CategoryConfig configures an entire category of rules
func (*CategoryConfig) UnmarshalYAML ¶
func (c *CategoryConfig) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML allows severity aliases (warn, info) in categories.
type Config ¶
type Config struct {
// Extends specifies rulesets to extend (e.g., "recommended", "all")
Extends []string `yaml:"extends,omitempty" json:"extends,omitempty"`
// Rules contains per-rule configuration
Rules []RuleEntry `yaml:"rules,omitempty" json:"rules,omitempty"`
// Categories contains per-category configuration
Categories map[string]CategoryConfig `yaml:"categories,omitempty" json:"categories,omitempty"`
// OutputFormat specifies the output format
OutputFormat OutputFormat `yaml:"output_format,omitempty" json:"output_format,omitempty"`
// CustomRules configures custom rule loading (requires customrules package import)
CustomRules *CustomRulesConfig `yaml:"custom_rules,omitempty" json:"custom_rules,omitempty"`
}
Config represents the linter configuration
func LoadConfig ¶
LoadConfig loads lint configuration from a YAML reader.
func LoadConfigFromFile ¶
LoadConfigFromFile loads lint configuration from a YAML file.
func (*Config) UnmarshalYAML ¶
UnmarshalYAML supports "extends" as string or list and severity aliases.
type ConfigurableRule ¶
type ConfigurableRule interface {
Rule
// ConfigSchema returns JSON Schema for rule-specific options
ConfigSchema() map[string]any
// ConfigDefaults returns default values for options
ConfigDefaults() map[string]any
}
ConfigurableRule indicates a rule has configurable options
type CustomRulesConfig ¶
type CustomRulesConfig struct {
// Paths are glob patterns for rule files (e.g., "./rules/*.ts")
Paths []string `yaml:"paths,omitempty" json:"paths,omitempty"`
// Timeout is the maximum execution time per rule (default: 30s)
Timeout time.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"`
}
CustomRulesConfig configures custom rule loading. This is the YAML-serializable configuration. The customrules package extends this with additional programmatic options like Logger.
type DocGenerator ¶
type DocGenerator[T any] struct { // contains filtered or unexported fields }
DocGenerator generates documentation from registered rules
func NewDocGenerator ¶
func NewDocGenerator[T any](registry *Registry[T]) *DocGenerator[T]
NewDocGenerator creates a new documentation generator
func (*DocGenerator[T]) GenerateAllRuleDocs ¶
func (g *DocGenerator[T]) GenerateAllRuleDocs() []*RuleDoc
GenerateAllRuleDocs generates documentation for all registered rules
func (*DocGenerator[T]) GenerateCategoryDocs ¶
func (g *DocGenerator[T]) GenerateCategoryDocs() map[string][]*RuleDoc
GenerateCategoryDocs groups rules by category
func (*DocGenerator[T]) GenerateRuleDoc ¶
func (g *DocGenerator[T]) GenerateRuleDoc(rule RuleRunner[T]) *RuleDoc
GenerateRuleDoc generates documentation for a single rule
func (*DocGenerator[T]) WriteJSON ¶
func (g *DocGenerator[T]) WriteJSON(w io.Writer) error
WriteJSON writes rule documentation as JSON
func (*DocGenerator[T]) WriteMarkdown ¶
func (g *DocGenerator[T]) WriteMarkdown(w io.Writer) error
WriteMarkdown writes rule documentation as Markdown
type DocumentInfo ¶
type DocumentInfo[T any] struct { // Document is the parsed document to lint Document T // Location is the absolute location (URL or file path) of the document // This is used for resolving relative references Location string // Index contains an index of various nodes from the provided document Index *openapi.Index }
DocumentInfo contains a document and its metadata for linting
func NewDocumentInfo ¶
func NewDocumentInfo[T any](doc T, location string) *DocumentInfo[T]
NewDocumentInfo creates a new DocumentInfo with the given document and location
func NewDocumentInfoWithIndex ¶
func NewDocumentInfoWithIndex[T any](doc T, location string, index *openapi.Index) *DocumentInfo[T]
NewDocumentInfoWithIndex creates a new DocumentInfo with a pre-computed index
type DocumentedRule ¶
type DocumentedRule interface {
Rule
// GoodExample returns YAML showing correct usage
GoodExample() string
// BadExample returns YAML showing incorrect usage
BadExample() string
// Rationale explains why this rule exists
Rationale() string
// FixAvailable returns true if the rule provides auto-fix suggestions
FixAvailable() bool
}
DocumentedRule provides extended documentation for a rule
type LintOptions ¶
type LintOptions struct {
// ResolveOptions contains options for reference resolution
// If nil, default options will be used
ResolveOptions *references.ResolveOptions
// VersionFilter is the document version (e.g., "3.0", "3.1")
// If set, only rules that apply to this version will be run
// Rules with nil/empty Versions() apply to all versions
VersionFilter *string
}
LintOptions contains runtime options for linting
type Linter ¶
type Linter[T any] struct { // contains filtered or unexported fields }
Linter is the main linting engine
func (*Linter[T]) FilterErrors ¶
FilterErrors applies rule-level overrides and match filters to any errors.
func (*Linter[T]) Lint ¶
func (l *Linter[T]) Lint(ctx context.Context, docInfo *DocumentInfo[T], preExistingErrors []error, opts *LintOptions) (*Output, error)
Lint runs all configured rules against the document
type Output ¶
type Output struct {
Results []error
Format OutputFormat
}
Output represents the result of linting
func (*Output) ErrorCount ¶
func (*Output) FormatJSON ¶
func (*Output) FormatText ¶
type OutputFormat ¶
type OutputFormat string
const ( OutputFormatText OutputFormat = "text" OutputFormatJSON OutputFormat = "json" )
type Registry ¶
type Registry[T any] struct { // contains filtered or unexported fields }
Registry holds registered rules
func (*Registry[T]) AllCategories ¶
AllCategories returns all unique categories
func (*Registry[T]) AllRuleIDs ¶
AllRuleIDs returns all registered rule IDs
func (*Registry[T]) AllRules ¶
func (r *Registry[T]) AllRules() []RuleRunner[T]
AllRules returns all registered rules
func (*Registry[T]) AllRulesets ¶
AllRulesets returns all registered ruleset names
func (*Registry[T]) GetRule ¶
func (r *Registry[T]) GetRule(id string) (RuleRunner[T], bool)
GetRule returns a rule by ID
func (*Registry[T]) GetRuleset ¶
GetRuleset returns rule IDs for a ruleset
func (*Registry[T]) Register ¶
func (r *Registry[T]) Register(rule RuleRunner[T])
Register registers a rule
func (*Registry[T]) RegisterRuleset ¶
RegisterRuleset registers a ruleset
func (*Registry[T]) RulesetsContaining ¶
RulesetsContaining returns names of rulesets that contain the given rule ID
type Rule ¶
type Rule interface {
// ID returns the unique identifier for this rule (e.g., "style-path-params")
ID() string
// Category returns the rule category (e.g., "style", "validation", "security")
Category() string
// Description returns a human-readable description of what the rule checks
Description() string
// Summary returns a short summary of what the rule checks
Summary() string
// Link returns an optional URL to documentation for this rule
Link() string
// DefaultSeverity returns the default severity level for this rule
DefaultSeverity() validation.Severity
// Versions returns the spec versions this rule applies to (nil = all versions)
Versions() []string
}
Rule represents a single linting rule
type RuleConfig ¶
type RuleConfig struct {
// Enabled controls whether the rule is active
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
// Severity overrides the default severity
Severity *validation.Severity `yaml:"severity,omitempty" json:"severity,omitempty"`
// ResolveOptions contains runtime options for reference resolution (not serialized)
// These are set by the linter engine when running rules
ResolveOptions *references.ResolveOptions `yaml:"-" json:"-"`
}
RuleConfig configures a specific rule
func (*RuleConfig) GetSeverity ¶
func (c *RuleConfig) GetSeverity(defaultSeverity validation.Severity) validation.Severity
GetSeverity returns the effective severity, falling back to default if not overridden
type RuleDoc ¶
type RuleDoc struct {
ID string `json:"id" yaml:"id"`
Category string `json:"category" yaml:"category"`
Summary string `json:"summary" yaml:"summary"`
Description string `json:"description" yaml:"description"`
Rationale string `json:"rationale,omitempty" yaml:"rationale,omitempty"`
Link string `json:"link,omitempty" yaml:"link,omitempty"`
DefaultSeverity string `json:"default_severity" yaml:"default_severity"`
Versions []string `json:"versions,omitempty" yaml:"versions,omitempty"`
GoodExample string `json:"good_example,omitempty" yaml:"good_example,omitempty"`
BadExample string `json:"bad_example,omitempty" yaml:"bad_example,omitempty"`
FixAvailable bool `json:"fix_available" yaml:"fix_available"`
ConfigSchema map[string]any `json:"config_schema,omitempty" yaml:"config_schema,omitempty"`
ConfigDefaults map[string]any `json:"config_defaults,omitempty" yaml:"config_defaults,omitempty"`
Rulesets []string `json:"rulesets" yaml:"rulesets"`
}
RuleDoc represents documentation for a single rule
type RuleEntry ¶
type RuleEntry struct {
ID string `yaml:"id" json:"id"`
Severity *validation.Severity `yaml:"severity,omitempty" json:"severity,omitempty"`
Disabled *bool `yaml:"disabled,omitempty" json:"disabled,omitempty"`
Match *regexp.Regexp `yaml:"match,omitempty" json:"match,omitempty"`
}
RuleEntry configures rule behavior in lint.yaml.
type RuleRunner ¶
type RuleRunner[T any] interface { Rule // Run executes the rule against the provided document // DocumentInfo provides both the document and its location for resolving external references // Returns any issues found as validation errors Run(ctx context.Context, docInfo *DocumentInfo[T], config *RuleConfig) []error }
RuleRunner is the interface rules must implement to execute their logic This is separate from Rule to allow different runner types for different specs