Documentation
¶
Overview ¶
Package check implements Vale's extension points.
Index ¶
- type Capitalization
- type Conditional
- type Consistency
- type Definition
- type Existence
- type FilterEnv
- type Manager
- func (mgr *Manager) AddRule(name string, rule Rule) error
- func (mgr *Manager) AddRuleFromFile(name, path string) error
- func (mgr *Manager) AssignNLP(f *core.File) nlp.Info
- func (mgr *Manager) HasScope(scope string) bool
- func (mgr *Manager) NeedsTagging() bool
- func (mgr *Manager) Rules() map[string]Rule
- type Metric
- type NLPToken
- type Occurrence
- type Readability
- type Repetition
- type Rule
- type Scope
- type Script
- type Selector
- type Sequence
- type Spelling
- type Substitution
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Capitalization ¶
type Capitalization struct {
Definition `mapstructure:",squash"`
// `match` (`string`): $title, $sentence, $lower, $upper, or a pattern.
Match string
Check func(s string, re *regexp2.Regexp) bool
// `style` (`string`): AP or Chicago; only applies when match is set to
// $title.
Style string
// `exceptions` (`array`): An array of strings to be ignored.
Exceptions []string
// `indicators` (`array`): An array of suffixes that indicate the next
// token should be ignored.
Indicators []string
// `threshold` (`float`): The minimum proportion of words that must be
// (un)capitalized for a sentence to be considered correct.
Threshold float64
// contains filtered or unexported fields
}
Capitalization checks the case of a string.
func NewCapitalization ¶
func NewCapitalization(cfg *core.Config, generic baseCheck, path string) (Capitalization, error)
NewCapitalization creates a new `capitalization`-based rule.
func (Capitalization) Fields ¶
func (o Capitalization) Fields() Definition
Fields provides access to the internal rule definition.
func (Capitalization) Pattern ¶
func (o Capitalization) Pattern() string
Pattern is the internal regex pattern used by this rule.
type Conditional ¶
type Conditional struct {
Definition `mapstructure:",squash"`
Exceptions []string
First string
Second string
Ignorecase bool
// contains filtered or unexported fields
}
Conditional ensures that the present of First ensures the present of Second.
func NewConditional ¶
func NewConditional(cfg *core.Config, generic baseCheck, path string) (Conditional, error)
NewConditional creates a new `conditional`-based rule.
func (Conditional) Fields ¶
func (c Conditional) Fields() Definition
Fields provides access to the internal rule definition.
func (Conditional) Pattern ¶
func (c Conditional) Pattern() string
Pattern is the internal regex pattern used by this rule.
type Consistency ¶
type Consistency struct {
Definition `mapstructure:",squash"`
// `either` (`map`): A map of `option 1: option 2` pairs, of which only one
// may appear.
Either map[string]string
// `nonword` (`bool`): Removes the default word boundaries (`\b`).
Nonword bool
// `ignorecase` (`bool`): Makes all matches case-insensitive.
Ignorecase bool
// contains filtered or unexported fields
}
Consistency ensures that the keys and values of Either don't both exist.
func NewConsistency ¶
func NewConsistency(cfg *core.Config, generic baseCheck, path string) (Consistency, error)
NewConsistency creates a new `consistency`-based rule.
func (Consistency) Fields ¶
func (o Consistency) Fields() Definition
Fields provides access to the internal rule definition.
func (Consistency) Pattern ¶
func (o Consistency) Pattern() string
Pattern is the internal regex pattern used by this rule.
type Definition ¶
type Definition struct {
Action core.Action
Description string
Extends string
Level string
Limit int
Link string
Message string
Name string
Scope []string
Selector Selector
}
Definition holds the common attributes of rule definitions.
type Existence ¶
type Existence struct {
Definition `mapstructure:",squash"`
Raw []string
Tokens []string
// `exceptions` (`array`): An array of strings to be ignored.
Exceptions []string
Append bool
IgnoreCase bool
Nonword bool
// contains filtered or unexported fields
}
Existence checks for the present of Tokens.
func NewExistence ¶
NewExistence creates a new `Rule` that extends `Existence`.
func (Existence) Fields ¶
func (e Existence) Fields() Definition
Fields provides access to the internal rule definition.
type FilterEnv ¶ added in v2.23.0
type FilterEnv struct {
Rules []Definition
}
FilterEnv is the environment passed to the `--filter` flag.
type Manager ¶
Manager controls the loading and validating of the check extension points.
func NewManager ¶
NewManager creates a new Manager and loads the rule definitions (that is, extended checks) specified by configuration.
func (*Manager) AddRuleFromFile ¶
AddRuleFromFile adds the given rule to the manager.
func (*Manager) HasScope ¶
HasScope returns `true` if the manager has a rule that applies to `scope`.
func (*Manager) NeedsTagging ¶ added in v2.10.3
NeedsTagging indicates if POS tagging is needed.
type Metric ¶ added in v2.12.0
type Metric struct {
Definition `mapstructure:",squash"`
// `metric` (`string`): the formula to be dynamically evaluated.
//
// Variables: # of words, # of sentences, etc.
Formula string
Condition string
// contains filtered or unexported fields
}
Metric implements arbitrary, readability-like formulas.
func (Metric) Fields ¶ added in v2.12.0
func (o Metric) Fields() Definition
Fields provides access to the internal rule definition.
type NLPToken ¶
type NLPToken struct {
Pattern string
Tag string
Skip int
Negate bool
// contains filtered or unexported fields
}
NLPToken represents a token of text with NLP-related attributes.
type Occurrence ¶
type Occurrence struct {
Definition `mapstructure:",squash"`
Token string
Max int
Min int
Ignorecase bool
// contains filtered or unexported fields
}
Occurrence counts the number of times Token appears.
func NewOccurrence ¶
func NewOccurrence(_ *core.Config, generic baseCheck, path string) (Occurrence, error)
NewOccurrence creates a new `occurrence`-based rule.
func (Occurrence) Fields ¶
func (o Occurrence) Fields() Definition
Fields provides access to the internal rule definition.
func (Occurrence) Pattern ¶
func (o Occurrence) Pattern() string
Pattern is the internal regex pattern used by this rule.
type Readability ¶
type Readability struct {
Definition `mapstructure:",squash"`
// `metrics` (`array`): One or more of Gunning Fog, Coleman-Liau,
// Flesch-Kincaid, SMOG, and Automated Readability.
Metrics []string
// `grade` (`float`): The highest acceptable score.
Grade float64
}
Readability checks the reading grade level of text.
func NewReadability ¶
func NewReadability(_ *core.Config, generic baseCheck, path string) (Readability, error)
NewReadability creates a new `readability`-based rule.
func (Readability) Fields ¶
func (o Readability) Fields() Definition
Fields provides access to the internal rule definition.
func (Readability) Pattern ¶
func (o Readability) Pattern() string
Pattern is the internal regex pattern used by this rule.
type Repetition ¶
type Repetition struct {
Definition `mapstructure:",squash"`
Tokens []string
Max int
Ignorecase bool
Alpha bool
// contains filtered or unexported fields
}
Repetition looks for repeated uses of Tokens.
func NewRepetition ¶
func NewRepetition(_ *core.Config, generic baseCheck, path string) (Repetition, error)
NewRepetition creates a new `repetition`-based rule.
func (Repetition) Fields ¶
func (o Repetition) Fields() Definition
Fields provides access to the internal rule definition.
func (Repetition) Pattern ¶
func (o Repetition) Pattern() string
Pattern is the internal regex pattern used by this rule.
type Rule ¶
type Rule interface {
Run(blk nlp.Block, file *core.File) ([]core.Alert, error)
Fields() Definition
Pattern() string
}
Rule represents in individual writing construct to enforce.
type Script ¶ added in v2.13.0
type Script struct {
Definition `mapstructure:",squash"`
Script string
// contains filtered or unexported fields
}
Script is Tango-based script.
see https://github.com/d5/tengo.
func (Script) Fields ¶ added in v2.13.0
func (s Script) Fields() Definition
Fields provides access to the internal rule definition.
type Selector ¶ added in v2.24.0
A Selector represents a named section of text.
func NewSelector ¶ added in v2.24.0
func (*Selector) ContainsString ¶ added in v2.24.0
ContainsString determines if all if sel's sections are in s.
type Sequence ¶
type Sequence struct {
Definition `mapstructure:",squash"`
Tokens []NLPToken
Ignorecase bool
// contains filtered or unexported fields
}
Sequence looks for a user-defined sequence of tokens.
func NewSequence ¶
NewSequence creates a new rule from the provided `baseCheck`.
func (Sequence) Fields ¶
func (s Sequence) Fields() Definition
Fields provides access to the rule definition.
type Spelling ¶
type Spelling struct {
Definition `mapstructure:",squash"`
Filters []*regexp.Regexp
Ignore []string
Exceptions []string
Dictionaries []string
Aff string
Dic string
Dicpath string
Threshold int
Custom bool
Append bool
// contains filtered or unexported fields
}
Spelling checks text against a Hunspell dictionary.
func NewSpelling ¶
NewSpelling creates a new `spelling`-based rule.
func (Spelling) Fields ¶
func (s Spelling) Fields() Definition
Fields provides access to the internal rule definition.
type Substitution ¶
type Substitution struct {
Definition `mapstructure:",squash"`
Exceptions []string
POS string
Swap map[string]string
Ignorecase bool
Nonword bool
// contains filtered or unexported fields
}
Substitution switches the values of Swap for its keys.
func NewSubstitution ¶
func NewSubstitution(cfg *core.Config, generic baseCheck, path string) (Substitution, error)
NewSubstitution creates a new `substitution`-based rule.
func (Substitution) Fields ¶
func (s Substitution) Fields() Definition
Fields provides access to the internal rule definition.
func (Substitution) Pattern ¶
func (s Substitution) Pattern() string
Pattern is the internal regex pattern used by this rule.