Documentation
¶
Overview ¶
Package rules applies rules and combines the results.
Index ¶
- Variables
- type Analyzer
- type AnalyzerConfig
- type Ignorer
- type Match
- type Report
- type ReportValue
- type Rule
- func (r *Rule) GetCondition() string
- func (r *Rule) GetGroups() []string
- func (r *Rule) GetIgnores() []string
- func (r *Rule) GetMaybeResults() []string
- func (r *Rule) GetMetadata() map[string]string
- func (r *Rule) GetName() string
- func (r *Rule) GetReadFiles() []string
- func (r *Rule) GetResults() []string
- type RuleSpec
- type Ruleset
- type RulesetSpec
- type WithGroups
- type WithMaybeResults
- type WithMetadata
- type WithReadFiles
- type YAMLListOrString
Constants ¶
This section is empty.
Variables ¶
View Source
var ValidateName = regexp.MustCompile(`^[a-z0-9][a-z0-9_.-]*[a-z0-9]$`).MatchString
ValidateName checks if a rule or ruleset name is valid.
Functions ¶
This section is empty.
Types ¶
type Analyzer ¶
type Analyzer struct {
// contains filtered or unexported fields
}
func NewAnalyzer ¶
func NewAnalyzer(rulesets []RulesetSpec, cnf *AnalyzerConfig) (*Analyzer, error)
type AnalyzerConfig ¶
type AnalyzerConfig struct {
CELEnvOptions []cel.EnvOption // Optional custom CEL environment options, replacing the default.
CELExpressionCache eval.Cache // Optional expression cache: ideally it should cover the expected expressions.
// DisableGitIgnore disables handling of .gitignore and .git/info/exclude files.
//
// The IgnoreDirs setting will still be respected, and certain directories will
// always be ignored (namely .git and node_modules). Rules that implement the
// Ignorer interface will also still be respected.
DisableGitIgnore bool
IgnoreDirs []string // Additional directory ignore rules, using git's exclude syntax.
DisableMetadata bool // Skip calculating or reporting rule metadata.
}
type Report ¶
type Report struct {
Ruleset string `json:"ruleset,omitempty"`
Path string `json:"path,omitempty"`
Result string `json:"result,omitempty"`
Error string `json:"error,omitempty"`
Rules []string `json:"rules,omitempty"`
Maybe bool `json:"maybe,omitempty"`
Groups []string `json:"groups,omitempty"`
ReadFiles []string `json:"read_files,omitempty"`
With map[string]ReportValue `json:"with,omitempty"`
}
Report contains results and other metadata after applying rules.
type ReportValue ¶
type ReportValue struct {
Value any `json:"value,omitempty"`
Error string `json:"error,omitempty"`
}
ReportValue contains a reported value or an error message.
type Rule ¶
type Rule struct {
Name string `yaml:"name,omitempty"`
When string `yaml:"when"`
Then YAMLListOrString `yaml:"then"`
Maybe YAMLListOrString `yaml:"maybe"`
With map[string]string `yaml:"with"`
Group string `yaml:"group"`
GroupList YAMLListOrString `yaml:"groups"`
Ignore YAMLListOrString `yaml:"ignore"`
ReadFiles []string `yaml:"read_files"`
}
Rule is the default implementation of a rule (see RuleSpec).
func (*Rule) GetCondition ¶
func (*Rule) GetIgnores ¶
func (*Rule) GetMaybeResults ¶
func (*Rule) GetMetadata ¶
func (*Rule) GetReadFiles ¶
func (*Rule) GetResults ¶
type RulesetSpec ¶
RulesetSpec defines a ruleset.
func LoadFromYAMLDir ¶
func LoadFromYAMLDir(fsys fs.FS, path string) ([]RulesetSpec, error)
LoadFromYAMLDir loads all YAML files in a directory and parses rulesets from them.
type WithGroups ¶
type WithGroups interface {
GetGroups() []string
}
WithGroups adds to a RuleSpec the feature of a rule having groups.
type WithMaybeResults ¶
type WithMaybeResults interface {
GetMaybeResults() []string
}
WithMaybeResults adds to a RuleSpec the possibility of a rule having uncertain results.
type WithMetadata ¶
WithMetadata adds to a RuleSpec the feature of a rule having metadata.
type WithReadFiles ¶
type WithReadFiles interface {
GetReadFiles() []string
}
type YAMLListOrString ¶
type YAMLListOrString []string
func (*YAMLListOrString) UnmarshalYAML ¶
func (l *YAMLListOrString) UnmarshalYAML(unmarshal func(interface{}) error) error
Click to show internal directories.
Click to hide internal directories.