Docs
Fixers
suggest
suggest
Learn how to create dynamic suggestions for your rules.
gofunc suggest(match string) []string
suggest
returns an array of suggested replacements for the matched text.
script
yamlaction: name: suggest params: - scriptName.tengo
The suggest
action allows you to define a custom suggestion script that will
be executed for each match. The script should return an array of strings called suggestions
.
Scripts are written in Tengo and are stored in the <StylesPath>/config/actions
directory.
Here’s an example script:
gotext := import("text") // `match` is provided by Vale and represents the rule's matched text. made := text.re_replace(`([A-Z]w+)([A-Z]w+)`, match, `$1-$2`) made = text.replace(made, "-", "_", 1) made = text.to_lower(made) // `suggestions` is required by Vale and represents the script's output. suggestions := [made]
We would save this script as CamelToSnake.tengo
and then reference it in
our rule:
yamlextends: existence message: "'%s' should be in snake_case." nonword: true level: error action: name: suggest params: - CamelToSnake.tengo tokens: - '[A-Z]w+[A-Z]w+'
spellings
yamlaction: name: suggest params: - spellings
spellings
returns the top 5 spelling suggestions for the matched text from
all active dictionaries.
Suggestions are ordered by calculating the Levenshtein distance between the matched text and the dictionary words.
On This Page