rule

package
v0.7.0-beta Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package rule contains functionality to create rules for evaluation by a linter

Index

Constants

View Source
const (
	PersonFirstRuleName string = "People-first"
	RegexRuleName       string = "Regex"
)
View Source
const PhrasePattern string = `(\s|\\s|[ ]|-)`

Regex to identify patterns that match a phrase (rather than just a word) Determination made based on presence of whitespace or a hyphen in the pattern Double backslash escapes the whitespace token '\s'

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

type Book struct {
	Name     string
	RuleSets []*CategorySet
}

Book is a collection of CategorySets

func NewBook

func NewBook(dir string) (*Book, error)

NewBook is a factory that loads rule files (.yml) from a directory to create a new rule book

func (*Book) GetTotalRuleCount

func (t *Book) GetTotalRuleCount() int

GetTotalRuleCount returns the total number of Rules from all RuleSets

func (*Book) NewCategorySet

func (t *Book) NewCategorySet() *CategorySet

NewCategorySet creates a new set of rules and adds it to the book

type CategorySet

type CategorySet struct {
	Category    string     `yaml:"Category"`
	Summary     string     `yaml:"Summary"`
	Detail      string     `yaml:"Detail"`
	Examples    []Example  `yaml:"Examples"`
	References  []string   `yaml:"References"`
	RuleConfigs []TypeInfo `yaml:"Rules"`
	Rules       []Checker
}

CategorySet is a collection of rules that share a common category and guidance

func NewCategorySet

func NewCategorySet(file []byte) (*CategorySet, error)

NewCategorySet is a factory that returns a RuleSet loaded from a YAML file.

func (*CategorySet) NewRule

func (t *CategorySet) NewRule(pattern string) (Checker, error)

NewRule creates a new rule with an initialised RegexChecker and adds it to the CategorySet

type CheckKind

type CheckKind int

CheckKind

const (
	// Word checks the lemma or text of the token for a match
	Word CheckKind = iota
	// Phrase checks the enclosing sentence of the token for a match
	Phrase
)

type CheckMatch

type CheckMatch struct {
	Term     string
	Position struct {
		Begin int
		End   int
	}
}

type Checker

type Checker interface {
	Init() error
	Kind() CheckKind
	Check(source *lex.Token) (CheckMatch, bool, string, error)
	PatternString() string
	String() string
}

type Example

type Example struct {
	Pass string `yaml:"Pass"`
	Fail string `yaml:"Fail"`
}

Example gives samples of text that pass and fail a set of rules

type PersonFirstChecker

type PersonFirstChecker struct {
	AdjectiveChecker RegexChecker
	// contains filtered or unexported fields
}

PersonFirstChecker evaluates a source token for person first language

func (*PersonFirstChecker) Check

func (t *PersonFirstChecker) Check(source *lex.Token) (match CheckMatch, isPass bool, advice string, err error)

Check implements RuleChecker

func (*PersonFirstChecker) Init

func (t *PersonFirstChecker) Init() error

func (PersonFirstChecker) Kind

func (t PersonFirstChecker) Kind() CheckKind

Kind implements RuleChecker

func (PersonFirstChecker) PatternString

func (t PersonFirstChecker) PatternString() string

PatternString implements RuleChecker

func (PersonFirstChecker) String

func (t PersonFirstChecker) String() string

Check implements String

type RegexChecker

type RegexChecker struct {
	Pattern     string
	Substitutes []string
	// contains filtered or unexported fields
}

RegexChecker evaluates a source token against a regex pattern

func (*RegexChecker) Check

func (t *RegexChecker) Check(source *lex.Token) (match CheckMatch, isPass bool, advice string, err error)

Check implements RuleChecker

func (*RegexChecker) Init

func (t *RegexChecker) Init() error

Init implements RuleChecker

func (RegexChecker) Kind

func (t RegexChecker) Kind() CheckKind

Kind implements RuleChecker

func (RegexChecker) PatternString

func (t RegexChecker) PatternString() string

Pattern implements RuleChecker

func (RegexChecker) String

func (t RegexChecker) String() string

String implements RuleChecker

type TypeInfo

type TypeInfo struct {
	TypeName string                 `yaml:"Type"`
	Fields   map[string]interface{} `yaml:"Fields"`
}

TypeInfo is used to help dynamically unmarshal structs from a yaml file

Jump to

Keyboard shortcuts

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