Documentation
¶
Index ¶
- func Categories() []string
- func ConfigureAll(cfg *core.Config) error
- func Count() int
- func HonorsSuppression(r Rule) bool
- func Register(rule Rule)
- func ResetState(list []Rule)
- type BaseRule
- func (r *BaseRule) Category() string
- func (r *BaseRule) Configure(settings map[string]any) error
- func (r *BaseRule) CreateViolation(file string, line int, message string) *core.Violation
- func (r *BaseRule) DefaultSeverity() core.Severity
- func (r *BaseRule) Description() string
- func (r *BaseRule) GetBoolSetting(key string, defaultVal bool) bool
- func (r *BaseRule) GetFloat64Setting(key string, defaultVal float64) float64
- func (r *BaseRule) GetIntSetting(key string, defaultVal int) int
- func (r *BaseRule) GetSetting(key string) (any, bool)
- func (r *BaseRule) GetStringSetting(key, defaultVal string) string
- func (r *BaseRule) Name() string
- type GoProjectRule
- type Registry
- func (r *Registry) All() []Rule
- func (r *Registry) Categories() []string
- func (r *Registry) ConfigureAll(cfg *core.Config) error
- func (r *Registry) Count() int
- func (r *Registry) CountByCategory() map[string]int
- func (r *Registry) Get(name string) (Rule, bool)
- func (r *Registry) GetByCategory(category string) []Rule
- func (r *Registry) GetEnabled(cfg *core.Config) []Rule
- func (r *Registry) Register(rule Rule) error
- type Rule
- type RuleInfo
- type StatefulRule
- type SuppressionExempt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Categories ¶
func Categories() []string
Categories returns all categories from the global registry
func ConfigureAll ¶
ConfigureAll configures all rules in the global registry
func HonorsSuppression ¶ added in v1.4.2
HonorsSuppression reports whether inline suppression comments apply to the given rule. All rules honor suppression unless they opt out explicitly via the SuppressionExempt interface.
func Register ¶
func Register(rule Rule)
Register adds a rule to the global registry and fails fast on duplicate registration. Package init functions cannot recover from an invalid rule registry, while Registry.Register remains available for dynamic callers.
func ResetState ¶ added in v1.4.2
func ResetState(list []Rule)
ResetState clears the accumulated state of every stateful rule in the list.
Types ¶
type BaseRule ¶
type BaseRule struct {
// contains filtered or unexported fields
}
BaseRule provides common functionality for rules
func NewBaseRule ¶
NewBaseRule creates a new base rule
func (*BaseRule) CreateViolation ¶
CreateViolation creates a new violation for this rule
func (*BaseRule) DefaultSeverity ¶
DefaultSeverity returns the default severity
func (*BaseRule) Description ¶
Description returns the rule description
func (*BaseRule) GetBoolSetting ¶
GetBoolSetting retrieves a bool setting
func (*BaseRule) GetFloat64Setting ¶
GetFloat64Setting retrieves a float64 setting
func (*BaseRule) GetIntSetting ¶
GetIntSetting retrieves an int setting
func (*BaseRule) GetSetting ¶
GetSetting retrieves a setting value
func (*BaseRule) GetStringSetting ¶
GetStringSetting retrieves a string setting
type GoProjectRule ¶ added in v1.4.2
type GoProjectRule interface {
Rule
AnalyzeGoProject(ctx *core.GoProjectContext) ([]*core.Violation, error)
RequiresSSA() bool
}
GoProjectRule is an optional package-level analysis interface for rules that need shared typed syntax or SSA. Implementations still satisfy Rule for API compatibility, but their AnalyzeFile method is not called by the check flow.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds all registered rules
func GlobalRegistry ¶
func GlobalRegistry() *Registry
GlobalRegistry returns the global registry instance
func (*Registry) Categories ¶
Categories returns all category names
func (*Registry) ConfigureAll ¶
ConfigureAll configures all rules from config. Every rule is configured exactly once with the category settings overlaid by its own settings, so that rule settings extend the category ones instead of replacing them, and so that a rule never keeps settings from a previously analyzed config.
func (*Registry) CountByCategory ¶
CountByCategory returns the number of rules per category
func (*Registry) GetByCategory ¶
GetByCategory returns all rules in a category
func (*Registry) GetEnabled ¶
GetEnabled returns rules that are enabled according to config
type Rule ¶
type Rule interface {
// Metadata
Name() string
Category() string
Description() string
DefaultSeverity() core.Severity
// Configuration
Configure(settings map[string]any) error
// Analysis - rules implement the ones they need
AnalyzeFile(ctx *core.FileContext) []*core.Violation
}
Rule is the interface that all rules must implement
func GetByCategory ¶
GetByCategory returns rules by category from the global registry
func GetEnabled ¶
GetEnabled returns enabled rules from the global registry
type RuleInfo ¶
RuleInfo contains metadata about a rule for display purposes. Auto-fix availability is not part of it: fixers live in pkg/fix (fix.DefaultRegistry), which the display layer consults directly.
type StatefulRule ¶ added in v1.4.2
type StatefulRule interface {
Rule
ResetState()
}
StatefulRule is an optional interface for rules that accumulate state across files (cross-file analysis). The check flow resets them before analyzing a project root, so that findings never depend on a previously analyzed root.
type SuppressionExempt ¶ added in v1.4.2
type SuppressionExempt interface {
SuppressionExempt() bool
}
SuppressionExempt is an optional interface for rules whose findings must not be silenced by inline comments (nolint:<rule> / <rule>: safe). Policy rules that forbid a pattern unconditionally implement it and return true.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package helpers provides shared utilities for rule implementations.
|
Package helpers provides shared utilities for rule implementations. |
|
Package rulestest builds throwaway Go modules for rule tests, so that a test can state the source it cares about and get a loaded project back.
|
Package rulestest builds throwaway Go modules for rule tests, so that a test can state the source it cares about and get a loaded project back. |