readability rule type calculates the reading grade level of text using standard readability metrics. It helps ensure content is accessible to your target audience.
How It Works
Thereadability rule processes text through one or more readability formulas, calculates an average grade level, and triggers an alert if the grade exceeds the specified threshold.
Parameters
An array of readability metrics to calculate. Options:
Gunning FogColeman-LiauFlesch-KincaidSMOGAutomated Readability
The maximum acceptable grade level. Alerts trigger when the calculated grade exceeds this value.
Examples
Flesch-Kincaid Grade Level
Use the most common readability metric:Multiple Metrics Average
Calculate an average across multiple metrics:SMOG for Technical Writing
Use SMOG index for technical documentation:Comprehensive Check
Use all available metrics for thorough evaluation:Accessible Content
Enforce lower grade level for accessible content:Readability Metrics Explained
Flesch-Kincaid Grade Level
- Formula:
0.39 × (words / sentences) + 11.8 × (syllables / words) - 15.59 - Best for: General content and documentation
- Range: Typically 0-18 (US grade levels)
Gunning Fog Index
- Formula:
0.4 × ((words / sentences) + 100 × (complex words / words)) - Best for: Business writing and journalism
- Range: 6+ (higher = more difficult)
Coleman-Liau Index
- Formula: Based on characters per word and words per sentence
- Best for: Technical documentation
- Range: Typically 1-16 (US grade levels)
SMOG (Simple Measure of Gobbledygook)
- Formula:
1.0430 × √(polysyllables × (30 / sentences)) + 3.1291 - Best for: Health and medical writing
- Range: Typically 4-18 (US grade levels)
Automated Readability Index
- Formula:
4.71 × (characters / words) + 0.5 × (words / sentences) - 21.43 - Best for: Technical and instructional content
- Range: Typically 1-14+ (US grade levels)
Use Cases
The
readability rule is ideal for:- Ensuring content accessibility
- Meeting style guide requirements
- Targeting specific audience education levels
- Comparing content complexity across documents
- Quality control for user-facing documentation
Scope Behavior
Grade Level Guidelines
Common grade level targets by content type:| Content Type | Target Grade | Metrics |
|---|---|---|
| General public | 6-8 | Flesch-Kincaid, SMOG |
| Marketing copy | 7-9 | Flesch-Kincaid, Gunning Fog |
| Technical docs | 9-11 | Coleman-Liau, Automated Readability |
| Academic papers | 12-14 | Multiple metrics |
| Medical/Legal | 10-12 | SMOG, Flesch-Kincaid |
Technical Details
Internally, thereadability rule (internal/check/readability.go:43-76):
- Creates a
Documentfrom the scoped text - Calculates each specified metric individually
- Sums all metric scores
- Divides by the number of metrics to get average
- Compares average against
gradethreshold - If exceeded, creates an alert at line 1
Alert Format
The%s placeholder in the message is replaced with the calculated grade level, formatted to two decimal places:
Multiple Metrics Averaging
When using multiple metrics, Vale calculates each independently and averages the results. This provides a more balanced assessment:Limitations
Readability metrics have limitations:
- They don’t understand context or meaning
- Technical jargon may inflate scores incorrectly
- Short documents may yield unreliable scores
- They assume English language conventions
- Formulas may disagree on the same text
Related Rule Types
- metric: Use for custom formulas based on document statistics
- occurrence: Use to count specific elements (like long sentences)
- sequence: Use to detect complex sentence structures