suggest | Vale
For the complete documentation index, see llms.txt. This page is also available as Markdown.

suggest

Learn how to compute a rule's suggestions.

func suggest(match string) []string

suggest returns replacements that have to be worked out from the match: the closest words in a dictionary, or whatever a script of your own decides.

spellings

action:
  name: suggest
  params:
    - spellings

The closest words to the match, up to six, by Levenshtein distance. The candidates are every dictionary the rule loads, the words in its ignore files, and the terms in the configuration's vocabularies; a project's own word comes first among candidates it ties with, spelled as the project spells it, so kubctl suggests kubectl before cubical. A capitalized match gets capitalized suggestions.

Ranking a dictionary is real work, so these suggestions are not computed while linting. Lint output leaves the alert's Suggestions empty, and an editor asks for them per alert. On a rule that extends spelling, a bare name: suggest means the same thing.

A script

action:
  name: suggest
  params:
    - CamelToSnake.tengo

Any other parameter names a Tengo script. Vale looks for it in <StylesPath>/config/actions first, then in the rule's own style directory, so a style can ship its scripts beside its rules. A script that is in neither place is a load-time error.

The script receives the matched text as match and must leave its answer in suggestions, an array of strings; anything in the array that is not a string is dropped. The text, fmt, and math modules are available to import.

Saved as CamelToSnake.tengo, the script serves this rule:

A script is compiled once per run and executed for each match.

Last updated