capitalization rule type checks the capitalization style of text against predefined patterns or case styles. It supports multiple built-in styles including title case, sentence case, and custom patterns.
How It Works
Thecapitalization rule compares text against a specified case style (like title case or sentence case) or a custom regex pattern. It can apply style guides like AP or Chicago and handle exceptions for proper nouns and technical terms.
Parameters
The capitalization style to enforce. Can be:
$title: Title case (with AP or Chicago style)$sentence: Sentence case$lower: Lowercase$upper: Uppercase- A custom regex pattern
The style guide to use for title case. Options are
AP or Chicago. Only applies when match: $title.An array of terms that should be ignored when checking capitalization.
An array of suffixes (like
:) that indicate the next token should be ignored. Used with sentence case.The minimum proportion of words that must match the style for text to be considered correct. Range: 0.0 to 1.0.
If
true, Vale will use your vocabulary files as additional exceptions.A regex pattern for prefixes to ignore when checking capitalization (e.g., list markers like
"a. ").Examples
Title Case with AP Style
Enforce AP-style title case for headings:Title Case with Chicago Style
Use Chicago Manual of Style for titles:AP vs Chicago: The main difference is treatment of prepositions and conjunctions. Chicago capitalizes prepositions of four or more letters, while AP typically uses lowercase for prepositions under four letters.
Sentence Case
Enforce sentence case for headings:indicators parameter tells Vale that after a colon, the next word should be capitalized (like starting a new sentence).
Uppercase Enforcement
Require all-caps for specific scopes:Lowercase Enforcement
Enforce lowercase (useful for tags or labels):Custom Pattern
Use a custom regex pattern for specific formats:With Prefix Handling
Handle numbered or lettered lists:Use Cases
The
capitalization rule is ideal for:- Enforcing heading style consistency
- Following specific style guides (AP, Chicago)
- Maintaining brand name capitalization
- Standardizing title formatting
- Ensuring proper sentence case in UI text
Threshold Parameter
Thethreshold parameter allows flexibility in enforcement. A threshold of 0.8 means 80% of words must match the style:
Technical Details
Internally, thecapitalization rule (internal/check/capitalization.go:114-142):
- Determines the check function based on
matchvalue - For
$title, creates aTitleConverterwith the specified style - For
$sentence, creates aSentenceConverterwith indicators - Applies the converter to the text
- Compares the result with the original text
- If mismatch exceeds threshold, creates an alert
Style Guide Details
AP Style Title Case
- Capitalize words of four letters or more
- Lowercase articles, short prepositions, and coordinating conjunctions
- Always capitalize the first and last word
Chicago Style Title Case
- Capitalize prepositions of four or more letters
- Lowercase articles and short conjunctions
- More liberal capitalization than AP
Automatic Suggestions
When usingaction.name: replace with $title or $sentence, Vale automatically provides the correctly-cased version as a suggestion:
Related Rule Types
- substitution: Use when you want to replace specific case violations with exact alternatives
- existence: Use when you want to flag specific improperly-cased terms
- consistency: Use when you want to ensure consistent capitalization of variants