Documentation ¶
Index ¶
- Variables
- func IsDirectiveOnlyLine(line string) bool
- type Options
- type Rule
- func (r *Rule) CanIgnoreLine(line string) bool
- func (r *Rule) ContainsCategory(cat string) bool
- func (r *Rule) Disabled() bool
- func (r *Rule) FindMatchIndexes(text string) [][]int
- func (r *Rule) Reason(finding string) string
- func (r *Rule) ReasonWithNote(finding string) string
- func (r *Rule) SetIncludeNote(includeNote bool)
- func (r *Rule) SetOptions(o Options)
- func (r *Rule) SetRegexp()
- type Severity
Constants ¶
This section is empty.
Variables ¶
var DefaultRules = []*Rule{}
DefaultRules are the default rules always used. This will be populated by the embed package on init
var TestErrorRule = Rule{ Name: "slave", Terms: []string{"slave"}, Alternatives: []string{"follower"}, Severity: 0, Options: Options{ WordBoundary: false, }, }
var TestInfoRule = Rule{ Name: "test", Terms: []string{"test"}, Alternatives: []string{"alternative"}, Severity: 2, Options: Options{ WordBoundary: false, }, }
var TestRule = Rule{ Name: "whitelist", Terms: []string{"whitelist", "white-list", "whitelisted", "white-listed"}, Alternatives: []string{"allowlist"}, Severity: 1, Options: Options{ WordBoundary: false, }, }
TestRule is only meant to be used in tests. TODO: Use test terms
Functions ¶
func IsDirectiveOnlyLine ¶
IsDirectiveOnlyLine returns a boolean value if the line contains only the wokeignore directive. For example, if a line is only a single-line comment containing wokeignore:rule=xyz with no other alphanumeric characters to the left of the directive, it will return true that it is a directive-only line. Any text to the right of the wokeignore directive will not be considered by woke for findings.
Types ¶
type Options ¶
type Options struct { WordBoundary bool `yaml:"word_boundary"` WordBoundaryStart bool `yaml:"word_boundary_start"` WordBoundaryEnd bool `yaml:"word_boundary_end"` IncludeNote *bool `yaml:"include_note"` Categories []string `yaml:"categories"` }
Options are options that can be configured and applied on a per-rule basis
type Rule ¶
type Rule struct { Name string `yaml:"name"` Terms []string `yaml:"terms"` Alternatives []string `yaml:"alternatives"` Note string `yaml:"note"` Severity Severity `yaml:"severity"` Options Options `yaml:"options"` // contains filtered or unexported fields }
Rule is a linter rule
func (*Rule) CanIgnoreLine ¶
CanIgnoreLine returns a boolean value if the line contains the ignore directive. For example, if a line has anywhere, wokeignore:rule=whitelist (should be commented out via whatever the language comment syntax is) it will not report that line in finding with the Rule with the name `whitelist` wokeignore:rule=whitelist
func (*Rule) ContainsCategory ¶
ContainsCategory denotes if the provided category exists in the rule's Options.Categories
func (*Rule) Disabled ¶
Disabled denotes if the rule is disabled If no terms are provided, this essentially disables the rule which is helpful for disabling default rules. Eventually, there should be a better way to disable a default rule, and then, if a rule has no Terms, it falls back to the Name.
func (*Rule) FindMatchIndexes ¶
FindMatchIndexes returns the start and end indexes for all rule findings for the text supplied.
func (*Rule) ReasonWithNote ¶
ReasonWithNote returns a human-readable reason for the rule finding with an additional note, if defined.
func (*Rule) SetIncludeNote ¶
SetIncludeNote populates IncludeNote attributte in Options Options.IncludeNote is ussed in ReasonWithNote If "include_note" is already defined for the rule in yaml, it will not be overridden
func (*Rule) SetOptions ¶
SetOptions sets new Options for the Rule and updates the regex.
type Severity ¶
type Severity int
Severity is a log severity
func (*Severity) MarshalJSON ¶
MarshalJSON to marshal Severity as a string
func (*Severity) UnmarshalYAML ¶
UnmarshalYAML to unmarshal severity string