Documentation
¶
Index ¶
Constants ¶
const ( // RulePrefix is a prefix of rule name RulePrefix = "rule." // DefaultFormat is a default format string DefaultFormat = "[{{.Level}}] {{.Rule}} {{.Message}}" // LevelError represents the error level reported by lint LevelError = "ERROR" // LevelWarning represents the warning level reported by lint LevelWarning = "WARN" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Report ReportConfig `hcl:"report,block"`
}
Config represents the configuration of the linter itself
type File ¶
type File struct { Path string Data []byte // Meta field means the annotation Meta string // File struct has Policy data // because policy applied to the file should be determined by each file Policy loader.Policy }
File represents the files to be linted It's converted from the arguments
type Linter ¶
type Linter struct {
// contains filtered or unexported fields
}
Linter is a linter structure
func (*Linter) PrintSummary ¶
PrintSummary prints the summary of all results of the entire Lint
type Policy ¶
type Policy struct { Config *Config `hcl:"config,block"` Rules Rules `hcl:"rule,block"` Outputs []Output `hcl:"output,block"` Debugs []Debug `hcl:"debug,block"` Remain hcl.Body `hcl:",remain"` }
Policy represents the rule set against config files of arguments
type Precondition ¶
type Precondition struct {
Cases []bool `hcl:"cases"`
}
Precondition represents a condition that determines whether the rule should be executed
type Report ¶
type Report struct { // Level takes ERROR or WARN // In case of ERROR, the report message of the failed rule is shown and the linter returns false // In case of WARN, the report message of the failed rule is shown and the linter returns true Level string `hcl:"level"` // Message is shown when the rule is failed Message string `hcl:"message"` }
Report represents the rule of reporting style
type ReportConfig ¶
type ReportConfig struct { Format string `hcl:"format,optional"` Style string `hcl:"style,optional"` Color bool `hcl:"color,optional"` }
ReportConfig represents the configuration of the report itself
type ReportLength ¶
type ReportLength struct { // Max length of RulePrefix + {{.Rule}} MaxRuleName int // Max length of {{.Level}} MaxLevel int // Max length of {{.Message}} MaxMessage int }
ReportLength is the information of the max length of each format strings
type Result ¶
type Result struct { Path string Items Items OK bool // RulesNotFound is a flag for rules not found RulesNotFound bool // Metadata is something notes related to Result Metadata string }
Result represents the execution result of Lint It's represented against one argument The result of each rules for the argument is stored in Items
type Rule ¶
type Rule struct { Name string `hcl:"name,label"` Description string `hcl:"description"` Dependencies []string `hcl:"depends_on,optional"` Precondition *Precondition `hcl:"precondition,block"` Conditions []bool `hcl:"conditions"` Report Report `hcl:"report,block"` Debugs []string `hcl:"debug,optional"` }
Rule represents the linting rule
func (*Rule) BuildMessage ¶
func (r *Rule) BuildMessage(cfg ReportConfig, length ReportLength) (string, error)
BuildMessage formats the results reported by linter.
func (*Rule) SkipCase ¶
SkipCase returns true if cases of a precondition block includes one or more failed cases
type Rules ¶
type Rules []Rule
Rules is the collenction of Rule object
func (*Rules) Sort ¶
func (r *Rules) Sort()
Sort sorts the rules based on its own dependencies
For example, in the case that these rules are defined like below, the order which the rules are executed should be as follows:
rule.a --- rule.b --- rule.c `- rule.d rule "a" { ... } rule "b" { depends_on = ["rule.a"] } rule "c" { depends_on = ["rule.b"] } rule "d" { depends_on = ["rule.a"] }
This implementation is based on the algorithm of topological sort