Skip to content

create-vale-rule: patterns are not RE2-only; backreferences and lookaround work on the vendored Vale #371

Description

@thecodedrift

From the 2026-09-21 dogfood, CLI 0.11.2, Vale 3.21.0, recipe topic v8.

Step 3 of the recipe says tokens and swap "compile as Go RE2 regular expressions" and "lookahead and lookbehind do not exist in RE2. A rule that needs 'X but not when followed by Y' cannot be written as a single substitution; split it or narrow with scope."

Measured on the vendored binary with throwaway rules under test: \1, (?= bar) and (?<=x ) all fire on the fail fixture and stay quiet on pass. A rule we shipped today depends on a backreference and passes its fixtures:

extends: existence
raw:
  - '\b(\w{3,}?)(s|es)?\b[^.!?\n]{0,60}[.!?] (It|We|They|That|This|You|I) (does not|doesn'\''t|can'\''t|cannot|don'\''t|do not|won'\''t|will not|never) \1(s|es)?\b'

That matches Vale's documented behavior: it compiles with Go regexp first and falls back to regexp2 when the pattern fails to compile, which is how lookaround and backreferences get through. The recipe's advice sends an author off to split a rule that could be one pattern.

What to do

  • Recipe: replace the RE2 paragraph with "Go regexp first, regexp2 fallback; lookaround and backreferences work but are slower, so keep them off hot paths and always prove them with a fixture."
  • Keep the word-boundary and hyphen notes in that step; those measured true.
  • No changeset (recipe only).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIRelated to the taskless CLIdocumentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions