rule

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRules = []*Rule{}

DefaultRules are the default rules always used. This will be populated by the embed package on init

View Source
var TestErrorRule = Rule{
	Name:         "slave",
	Terms:        []string{"slave"},
	Alternatives: []string{"follower"},
	Severity:     0,
	Options: Options{
		WordBoundary: false,
	},
}
View Source
var TestInfoRule = Rule{
	Name:         "test",
	Terms:        []string{"test"},
	Alternatives: []string{"alternative"},
	Severity:     2,
	Options: Options{
		WordBoundary: false,
	},
}
View Source
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 added in v0.13.0

func IsDirectiveOnlyLine(line string) bool

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 added in v0.4.0

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 added in v0.1.4

func (r *Rule) CanIgnoreLine(line string) bool

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 added in v0.14.0

func (r *Rule) ContainsCategory(cat string) bool

ContainsCategory denotes if the provided category exists in the rule's Options.Categories

func (*Rule) Disabled added in v0.1.16

func (r *Rule) Disabled() bool

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 added in v0.1.14

func (r *Rule) FindMatchIndexes(text string) [][]int

FindMatchIndexes returns the start and end indexes for all rule findings for the text supplied.

func (*Rule) Reason

func (r *Rule) Reason(finding string) string

Reason returns a human-readable reason for the rule finding

func (*Rule) ReasonWithNote

func (r *Rule) ReasonWithNote(finding string) string

ReasonWithNote returns a human-readable reason for the rule finding with an additional note, if defined.

func (*Rule) SetIncludeNote added in v0.9.0

func (r *Rule) SetIncludeNote(includeNote bool)

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 added in v0.10.0

func (r *Rule) SetOptions(o Options)

SetOptions sets new Options for the Rule and updates the regex.

func (*Rule) SetRegexp added in v0.1.13

func (r *Rule) SetRegexp()

SetRegexp populates the regex for matching this rule. This is meant to be idempotent, so calling it multiple times won't update the regex

type Severity

type Severity int

Severity is a log severity

const (
	// SevError translates to Error
	// This will be the default severity
	SevError Severity = iota
	// SevWarn translates to Warning
	SevWarn
	// SevInfo translates to Info
	SevInfo
)

func NewSeverity

func NewSeverity(s string) Severity

NewSeverity turns a string into a Severity

func (*Severity) Colorize

func (s *Severity) Colorize() string

Colorize returns a the Severity as a colorized string

func (*Severity) MarshalJSON added in v0.2.0

func (s *Severity) MarshalJSON() ([]byte, error)

MarshalJSON to marshal Severity as a string

func (Severity) String

func (s Severity) String() string

func (*Severity) UnmarshalYAML

func (s *Severity) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML to unmarshal severity string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL