replace
Learn how to write a rule's replacements into the rule.
func replace(match string) []stringreplace returns the replacements listed in the rule.
extends: existence
message: "Use '%s' for '%s'."
action:
name: replace
params:
- color
tokens:
- colourA parameter can name the token's capture groups, $1, $2, and the whole match as $0; see the token's groups. Several parameters are several suggestions. The message joins them, 'color or hue', and an editor offers each as its own quick fix.
Rules that extend substitution or capitalization know their own replacement, so the parameters can be left out:
extends: substitution
message: "Use '%s' instead of '%s'."
action:
name: replace
swap:
Javascript: JavaScriptA substitution entry whose value is written as alternatives, color|hue, yields one suggestion per alternative.
With matchcase set on the rule, each replacement takes the case of the text it replaces, so a swap written as a-ok still suggests A-OK for A OK. The capitalization check ignores that setting: it decides the case, and changing its suggestion's case would undo the correction.
Last updated