check

package
v2.30.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package check implements Vale's extension points.

Index

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.

func (Capitalization) Run

func (o Capitalization) Run(blk nlp.Block, _ *core.File) ([]core.Alert, error)

Run checks the capitalization style of the provided text.

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.

func (Conditional) Run

func (c Conditional) Run(blk nlp.Block, f *core.File) ([]core.Alert, error)

Run evaluates the given conditional statement.

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.

func (Consistency) Run

func (o Consistency) Run(blk nlp.Block, f *core.File) ([]core.Alert, error)

Run looks for inconsistent use of a user-defined regex.

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

func NewExistence(cfg *core.Config, generic baseCheck, path string) (Existence, error)

NewExistence creates a new `Rule` that extends `Existence`.

func (Existence) Fields

func (e Existence) Fields() Definition

Fields provides access to the internal rule definition.

func (Existence) Pattern

func (e Existence) Pattern() string

Pattern is the internal regex pattern used by this rule.

func (Existence) Run

func (e Existence) Run(blk nlp.Block, _ *core.File) ([]core.Alert, error)

Run executes the the `existence`-based rule.

This is simplest of the available extension points: it looks for any matches of its internal `pattern` (calculated from `NewExistence`) against the provided text.

type FilterEnv added in v2.23.0

type FilterEnv struct {
	Rules []Definition
}

FilterEnv is the environment passed to the `--filter` flag.

type Manager

type Manager struct {
	Config *core.Config
	// contains filtered or unexported fields
}

Manager controls the loading and validating of the check extension points.

func NewManager

func NewManager(config *core.Config) (*Manager, error)

NewManager creates a new Manager and loads the rule definitions (that is, extended checks) specified by configuration.

func (*Manager) AddRule

func (mgr *Manager) AddRule(name string, rule Rule) error

AddRule adds the given rule to the manager.

func (*Manager) AddRuleFromFile

func (mgr *Manager) AddRuleFromFile(name, path string) error

AddRuleFromFile adds the given rule to the manager.

func (*Manager) AssignNLP added in v2.10.3

func (mgr *Manager) AssignNLP(f *core.File) nlp.Info

AssignNLP determines what NLP tasks a file needs.

func (*Manager) HasScope

func (mgr *Manager) HasScope(scope string) bool

HasScope returns `true` if the manager has a rule that applies to `scope`.

func (*Manager) NeedsTagging added in v2.10.3

func (mgr *Manager) NeedsTagging() bool

NeedsTagging indicates if POS tagging is needed.

func (*Manager) Rules

func (mgr *Manager) Rules() map[string]Rule

Rules are all of the Manager's compiled `Rule`s.

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 NewMetric added in v2.12.0

func NewMetric(_ *core.Config, generic baseCheck, path string) (Metric, error)

NewMetric creates a new `metric`-based rule.

func (Metric) Fields added in v2.12.0

func (o Metric) Fields() Definition

Fields provides access to the internal rule definition.

func (Metric) Pattern added in v2.12.0

func (o Metric) Pattern() string

Pattern is the internal regex pattern used by this rule.

func (Metric) Run added in v2.12.0

func (o Metric) Run(_ nlp.Block, f *core.File) ([]core.Alert, error)

Run calculates the readability level of the given text.

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.

func (Occurrence) Run

func (o Occurrence) Run(blk nlp.Block, _ *core.File) ([]core.Alert, error)

Run checks the number of occurrences of a user-defined regex against a certain threshold.

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.

func (Readability) Run

func (o Readability) Run(blk nlp.Block, _ *core.File) ([]core.Alert, error)

Run calculates the readability level of the given text.

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.

func (Repetition) Run

func (o Repetition) Run(blk nlp.Block, _ *core.File) ([]core.Alert, error)

Run executes the the `repetition`-based rule.

The rule looks for repeated matches of its regex -- such as "this this".

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 Scope added in v2.24.0

type Scope struct {
	Selectors map[string][]Selector
}

func NewScope added in v2.24.0

func NewScope(value []string) Scope

func (Scope) Matches added in v2.24.0

func (s Scope) Matches(blk nlp.Block) bool

Macthes the scope `s` matches `s2`.

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 NewScript added in v2.13.0

func NewScript(_ *core.Config, generic baseCheck, path string) (Script, error)

NewScript creates a new `script`-based rule.

func (Script) Fields added in v2.13.0

func (s Script) Fields() Definition

Fields provides access to the internal rule definition.

func (Script) Pattern added in v2.13.0

func (s Script) Pattern() string

Pattern is the internal regex pattern used by this rule.

func (Script) Run added in v2.13.0

func (s Script) Run(blk nlp.Block, _ *core.File) ([]core.Alert, error)

Run executes the given script and returns its Alerts.

type Selector added in v2.24.0

type Selector struct {
	Value   []string // e.g., text.comment.line.py
	Negated bool
}

A Selector represents a named section of text.

func NewSelector added in v2.24.0

func NewSelector(value []string) Selector

func (*Selector) Contains added in v2.24.0

func (s *Selector) Contains(sel Selector) bool

Contains determines if all if sel's sections are in s.

func (*Selector) ContainsString added in v2.24.0

func (s *Selector) ContainsString(scope []string) bool

ContainsString determines if all if sel's sections are in s.

func (*Selector) Equal added in v2.24.0

func (s *Selector) Equal(sel Selector) bool

Equal determines if sel == s.

func (*Selector) Has added in v2.24.0

func (s *Selector) Has(scope string) bool

Has determines if s has a part equal to scope.

func (*Selector) Sections added in v2.24.0

func (s *Selector) Sections() []string

Sections splits a Selector into its parts -- e.g., text.comment.line.py -> []string{"text", "comment", "line", "py"}.

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

func NewSequence(cfg *core.Config, generic baseCheck, path string) (Sequence, error)

NewSequence creates a new rule from the provided `baseCheck`.

func (Sequence) Fields

func (s Sequence) Fields() Definition

Fields provides access to the rule definition.

func (Sequence) Pattern

func (s Sequence) Pattern() string

Pattern is the internal regex pattern used by this rule.

func (Sequence) Run

func (s Sequence) Run(blk nlp.Block, f *core.File) ([]core.Alert, error)

Run looks for the user-defined sequence of tokens.

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

func NewSpelling(cfg *core.Config, generic baseCheck, path string) (Spelling, error)

NewSpelling creates a new `spelling`-based rule.

func (Spelling) Fields

func (s Spelling) Fields() Definition

Fields provides access to the internal rule definition.

func (Spelling) Pattern

func (s Spelling) Pattern() string

Pattern is the internal regex pattern used by this rule.

func (Spelling) Run

func (s Spelling) Run(blk nlp.Block, _ *core.File) ([]core.Alert, error)

Run performs spell-checking on the provided text.

func (Spelling) Suggest added in v2.23.1

func (s Spelling) Suggest(word string) []string

Pattern is the internal regex pattern used by this rule.

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.

func (Substitution) Run

func (s Substitution) Run(blk nlp.Block, _ *core.File) ([]core.Alert, error)

Run executes the the `substitution`-based rule.

The rule looks for one pattern and then suggests a replacement.

Jump to

Keyboard shortcuts

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