repetition rule type identifies repeated consecutive occurrences of tokens. This helps catch common writing mistakes like “the the” while being smart about sentence boundaries.
How It Works
Therepetition rule searches for consecutive matches of specified patterns. It tracks matches and triggers an alert when the same token appears multiple times in a row, exceeding the specified threshold.
Parameters
An array of regex patterns to match. The rule will look for consecutive occurrences of matches.
The maximum number of consecutive repetitions allowed. A value of
0 means any repetition triggers an alert.Makes pattern matching case-insensitive when set to
true.When
true, only matches that consist of letters trigger alerts. This filters out repeated punctuation or numbers.An array of strings or patterns that should not trigger alerts even if repeated.
If
true, Vale will use your vocabulary files as additional exceptions.Examples
Basic Word Repetition
Catch any repeated word:- “the the document”
- “This This is wrong”
Allowing Some Repetition
Allow deliberate repetition (e.g., “very very important”):Alphabetic Only
Only flag repeated words, not punctuation or numbers:With Exceptions
Allow specific repeated words (like “had had” in past perfect):Case-Sensitive Repetition
Only flag exact case matches:Use Cases
The
repetition rule is ideal for:- Catching accidental word duplication during editing
- Identifying copy-paste errors
- Enforcing clarity by preventing stuttered text
- Quality control for technical documentation
Sentence Boundary Detection
The
repetition rule is smart about sentence boundaries. It only flags repetitions within the same sentence, avoiding false positives like:“Redis is fast. Redis can handle millions of requests.”If the repeated words span multiple sentences (detected by nlp.SentenceTokenizer), no alert is triggered.Technical Details
Internally, therepetition rule (internal/check/repetition.go:61-125):
- Compiles all tokens into a single regex pattern with alternation
- Finds all matches in the text using
FindAllStringIndex - Compares each match with the previous match
- Increments a counter when consecutive matches are identical
- When count exceeds
max, checks if the span crosses sentence boundaries - If within a single sentence, creates an alert for the full repeated span
ignorecase setting:
alpha parameter filters matches through core.IsLetter() to ensure only alphabetic strings trigger alerts.
Alert Span
When a repetition is detected, the alert spans from the start of the first occurrence to the end of the last occurrence, making it easy to see the full repeated phrase.Related Rule Types
- existence: Use when you want to detect any occurrence, not just repetitions
- occurrence: Use when you want to count total occurrences, not consecutive ones
- sequence: Use when you need to match specific patterns of tokens in sequence