spelling rule type performs spell-checking using Hunspell dictionaries. It supports custom dictionaries, filters, and exception lists for flexible spell-checking configurations.
How It Works
Thespelling rule loads Hunspell dictionaries (.dic and .aff files), tokenizes text into words, and checks each word against the dictionary. Words not found in the dictionary (and not in exception lists) trigger alerts.
Parameters
An array of dictionary names to load (without extensions). Vale looks for corresponding
.dic and .aff files.Direct path to a Hunspell
.aff (affix) file. Used with dic for custom dictionaries.Direct path to a Hunspell
.dic (dictionary) file. Used with aff for custom dictionaries.Path to a directory containing Hunspell dictionary files. Vale searches this directory for dictionaries.
An array of regex patterns. Words matching any filter are skipped during spell-checking.
Path(s) to word list files. Words in these files are excluded from spell-checking.
When
true, disables default filters. When false, applies built-in filters for camelCase, ACRONYMS, and non-alphabetic characters.When
true, includes default dictionaries in addition to specified ones.Examples
Basic Spell Checking
Use a custom dictionary:Custom Dictionary with Suggestions
Enable spelling suggestions:With Custom Filters
Filter out specific patterns:Using Ignore Files
Exclude project-specific terms:Direct Dictionary Paths
Specify exact dictionary files:Dictionary Path
Use a custom dictionary directory:Multiple Dictionaries
Combine multiple dictionaries:Default Filters
Whencustom: false (default), Vale applies these built-in filters:
- CamelCase:
[A-Z]{1}[a-z]+[A-Z]+\w+- Skips camelCase and PascalCase - All Caps:
[A-Z]+$- Skips ACRONYMS - Non-Alpha:
[^a-zA-Z_']- Skips words with numbers or special chars
custom: true to disable these and only use your own filters.
Ignore File Paths
Vale searches for ignore files in multiple locations:- Absolute paths (if provided)
- Relative to
StylesPath - Relative to
StylesPath/config/ignore/
Vale.Spelling, Vale automatically checks config/ignore/ for all .txt files.
Use Cases
The
spelling rule is ideal for:- Standard spell-checking with language dictionaries
- Technical documentation with custom terminology
- Multi-language content
- Brand name validation
- Code documentation with programming terms
Vale.Spelling
Vale includes a built-inVale.Spelling rule that:
- Automatically loads default dictionaries from
config/dictionaries/ - Reads ignore files from
config/ignore/ - Respects your vocabulary files (
accept.txt) - Works out of the box with no configuration
Technical Details
Internally, thespelling rule (internal/check/spelling.go:165-199):
- Creates a Hunspell spell checker with specified dictionaries
- Loads ignore files using
AddWordListFile - Tokenizes text using
nlp.WordTokenizer - Applies filters to each token
- Checks remaining tokens with
gs.Spell(word) - For misspellings, creates alerts with optional suggestions
Suggestion Action
When usingaction.name: suggest, Vale uses Hunspell’s suggestion engine:
Dictionary File Format
Hunspell dictionaries consist of two files:.dic file (Dictionary)
.aff file (Affix)
Custom Filters Example
Complex filter patterns for code documentation:Vocabulary Integration
Vale automatically adds terms from youraccept.txt vocabulary files as exceptions:
vocab: true (default).
Performance Considerations
Related Rule Types
- existence: Use to flag specific misspellings with corrections
- substitution: Use to suggest specific replacements for common typos
- consistency: Use to enforce consistent spelling of variant terms