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

replace

Learn how to write a rule's replacements into the rule.

func replace(match string) []string

replace returns the replacements listed in the rule.

extends: existence
message: "Use '%s' for '%s'."
action:
  name: replace
  params:
    - color
tokens:
  - colour

A 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: JavaScript

A 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