Actions
Create dynamic suggestions for your rules with Actions.
vale-ls
for an easy way to integrate Actions into your favorite text editor.Actions provide a way for users to define dynamic fixes for their custom rules that show up in the CLI and LSP-based integrations.
In the Sublime Text example above, the “Quick Fix” menu is powered by the action defined in the rule definition:
yamlaction: name: replace
See the documentation on each action
type for more information:
Name | Description |
---|---|
suggest | An array of dynamically-computed suggestions. |
replace | An array of static suggestions. Supported by default in substitution and capitalization . |
remove | Remove the matched text. |
edit | In-place edits of the matched text. |
CLI
Most Vale rules are based on static suggestions—for example,
yamlextends: substitution message: "Use '%s' instead of '%s'." level: error action: name: replace swap: Javascript: JavaScript
Here, the action
is a to replace Javascript
with JavaScript
. In such
cases, we know what we want to suggest to the user ahead of time and Vale can
easily generate the appropriate output message.
However, there are cases in which we don’t know the appropriate suggestion ahead of time. For example, consider the following rule:
yamlextends: existence message: "'%s' should be '%s'." level: error action: name: edit params: - regex - '(w+)_(w+)' - '$1-$2' tokens: - 'w+_w+'
This rule is designed to catch instances of snake_case
and suggest that the
user convert to kebab-case
. In this case, the exact suggestion is dependent
on a string transformation that needs to be computed at runtime.
Using the edit
action allows us to define a rule that can dynamically
generate suggestions based on the matched text in CLI output:
As you can see, the CLI output is dynamically computing the suggestion based on the matched text.
LSP
In both static and dynamic cases, any application that uses the Vale Language Server will be able to provide the user with a list of “Quick Fixes” that can be applied to the document.
On This Page