consistency rule type ensures that variant spellings or terms aren’t mixed within the same document. When multiple valid options exist, this rule enforces picking one and sticking with it.
How It Works
Theconsistency rule tracks pairs of alternatives defined in the either map. If both variants appear in the same file, it triggers an alert. This is file-scoped, meaning consistency is enforced across the entire document.
Parameters
A map of
option1: option2 pairs. Only one option from each pair should appear in a document.Makes pattern matching case-insensitive when set to
true.Removes the default word boundaries (
\b) when set to true.Examples
Spelling Consistency
Enforce consistent spelling across British and American English:Smart Quotes vs Straight Quotes
Ensure consistent use of quote styles:Hyphenation Consistency
Enforce consistent hyphenation of compound terms:Brand Name Variants
Ensure consistent brand name usage:Date Format Consistency
Enforce consistent date formatting:Use Cases
The
consistency rule is ideal for:- Enforcing spelling consistency (US vs UK English)
- Maintaining consistent hyphenation
- Ensuring uniform quote style
- Preventing mixed terminology
- Standardizing date/time formats
File-Level Scope
Technical Details
Internally, theconsistency rule (internal/check/consistency.go:80-112):
- Creates a separate check step for each key-value pair in
either - Compiles each pair into a regex with named capture groups
- Stores all matches in the file’s
Sequencesarray - If both names from a pair appear in
Sequences, triggers an alert - Uses
core.AllStringsInSlice()to check for complete pairs
Multiple Pairs
You can define multiple pairs in a single rule. Vale will check each pair independently:Case Sensitivity
By default,consistency rules are case-sensitive. Set ignorecase: true to treat “Color” and “color” as the same variant:
Related Rule Types
- substitution: Use when you want to enforce one specific variant (rather than just consistency)
- existence: Use when you want to flag specific terms regardless of alternatives
- spelling: Use for general spell-checking with dictionaries