|
| 1 | +# Spelling Guide |
| 2 | + |
| 3 | +This document explains how we handle spelling in the Torrust Tracker Deploy project using CSpell. |
| 4 | + |
| 5 | +## 🎯 Overview |
| 6 | + |
| 7 | +We use [CSpell](https://cspell.org/) for spell checking across all project files including documentation, comments, and code identifiers. This helps maintain consistency and professionalism in our codebase. |
| 8 | + |
| 9 | +## 📋 Configuration |
| 10 | + |
| 11 | +### CSpell Configuration |
| 12 | + |
| 13 | +Our spell checking is configured through `cspell.json` in the project root: |
| 14 | + |
| 15 | +```json |
| 16 | +{ |
| 17 | + "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", |
| 18 | + "version": "0.2", |
| 19 | + "dictionaryDefinitions": [ |
| 20 | + { |
| 21 | + "name": "project-words", |
| 22 | + "path": "./project-words.txt", |
| 23 | + "addWords": true |
| 24 | + } |
| 25 | + ], |
| 26 | + "dictionaries": ["project-words"], |
| 27 | + "ignorePaths": ["target", "/project-words.txt"] |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +### Project Dictionary |
| 32 | + |
| 33 | +The `project-words.txt` file contains: |
| 34 | + |
| 35 | +- Technical terms specific to our domain |
| 36 | +- Proper nouns (company names, product names) |
| 37 | +- Acronyms and abbreviations |
| 38 | +- Valid identifiers that aren't in standard dictionaries |
| 39 | + |
| 40 | +## 🚀 Running Spell Checks |
| 41 | + |
| 42 | +### Via Linting System |
| 43 | + |
| 44 | +```bash |
| 45 | +# Run CSpell individually |
| 46 | +cargo run --bin linter cspell |
| 47 | + |
| 48 | +# Run all linters including CSpell |
| 49 | +cargo run --bin linter all |
| 50 | +``` |
| 51 | + |
| 52 | +### Direct CSpell Commands |
| 53 | + |
| 54 | +```bash |
| 55 | +# Check all files |
| 56 | +cspell . |
| 57 | + |
| 58 | +# Check with suggestions and context |
| 59 | +cspell . --no-progress --show-suggestions --show-context |
| 60 | + |
| 61 | +# Check specific files |
| 62 | +cspell "src/**/*.rs" "docs/**/*.md" |
| 63 | + |
| 64 | +# Get list of unknown words |
| 65 | +cspell --words-only --unique . |
| 66 | +``` |
| 67 | + |
| 68 | +## 🔧 Fixing Spelling Issues |
| 69 | + |
| 70 | +### 1. Fix Actual Misspellings |
| 71 | + |
| 72 | +For genuine spelling errors, fix them directly in the source files. |
| 73 | + |
| 74 | +### 2. Add Valid Terms to Dictionary |
| 75 | + |
| 76 | +For legitimate technical terms, proper nouns, or domain-specific vocabulary: |
| 77 | + |
| 78 | +```bash |
| 79 | +# Add words to project-words.txt (one per line, sorted alphabetically) |
| 80 | +echo "kubernetes" >> project-words.txt |
| 81 | +echo "dockerfile" >> project-words.txt |
| 82 | +sort -u project-words.txt -o project-words.txt |
| 83 | +``` |
| 84 | + |
| 85 | +### 3. Handle Special Cases |
| 86 | + |
| 87 | +#### Code Identifiers |
| 88 | + |
| 89 | +Valid variable names, function names, and identifiers should be added to the dictionary: |
| 90 | + |
| 91 | +```text |
| 92 | +# Examples in project-words.txt |
| 93 | +ansible |
| 94 | +containerd |
| 95 | +rustfmt |
| 96 | +shellcheck |
| 97 | +torrust |
| 98 | +``` |
| 99 | + |
| 100 | +#### Tokens and Keys |
| 101 | + |
| 102 | +For security tokens, API keys, and similar strings, there are several approaches: |
| 103 | + |
| 104 | +1. **Add to Dictionary (Recommended)**: |
| 105 | + |
| 106 | + ```text |
| 107 | + # In project-words.txt - for test/fixture tokens only |
| 108 | + AAAAB |
| 109 | + EAAAADAQABAAABAQC |
| 110 | + ``` |
| 111 | + |
| 112 | +2. **Use CSpell Ignore Comments**: |
| 113 | + |
| 114 | + ```rust |
| 115 | + // cspell:disable-next-line |
| 116 | + const API_TOKEN: &str = "abc123def456ghi789"; |
| 117 | + |
| 118 | + /* cspell:disable */ |
| 119 | + const COMPLEX_TOKEN: &str = "very-long-generated-token-here"; |
| 120 | + /* cspell:enable */ |
| 121 | + ``` |
| 122 | + |
| 123 | +3. **Configuration Patterns**: |
| 124 | + |
| 125 | + ```json |
| 126 | + { |
| 127 | + "ignoreRegExpList": ["/auth_token: .*/g", "/api[_-]key: .*/gi"] |
| 128 | + } |
| 129 | + ``` |
| 130 | + |
| 131 | +## 📝 Best Practices |
| 132 | + |
| 133 | +### Do Add to Dictionary |
| 134 | + |
| 135 | +- ✅ Technical terms: `kubernetes`, `dockerfile`, `ansible` |
| 136 | +- ✅ Project names: `torrust`, `opentofu` |
| 137 | +- ✅ Tool names: `rustfmt`, `shellcheck`, `yamllint` |
| 138 | +- ✅ Domain concepts: `provisioning`, `infra` |
| 139 | +- ✅ Test fixture data (non-sensitive) |
| 140 | + |
| 141 | +### Don't Add to Dictionary |
| 142 | + |
| 143 | +- ❌ Actual misspellings |
| 144 | +- ❌ Typos in variable names |
| 145 | +- ❌ Real secrets or production tokens |
| 146 | +- ❌ Random strings that could mask real errors |
| 147 | + |
| 148 | +### Guidelines for Adding Words |
| 149 | + |
| 150 | +1. **Be Conservative**: Only add words you're confident are correct |
| 151 | +2. **Use Lowercase**: Add words in lowercase unless they're proper nouns |
| 152 | +3. **Check Alternatives**: Consider if there's a standard spelling first |
| 153 | +4. **Document Context**: Add comments in `project-words.txt` for unusual terms |
| 154 | + |
| 155 | +Example `project-words.txt` structure: |
| 156 | + |
| 157 | +```text |
| 158 | +# Infrastructure and DevOps |
| 159 | +ansible |
| 160 | +containerd |
| 161 | +dockerfile |
| 162 | +kubernetes |
| 163 | +multipass |
| 164 | +opentofu |
| 165 | +
|
| 166 | +# Project-specific terms |
| 167 | +torrust |
| 168 | +rustfmt |
| 169 | +shellcheck |
| 170 | +
|
| 171 | +# Test fixtures (non-sensitive) |
| 172 | +testkey |
| 173 | +mocksecret |
| 174 | +``` |
| 175 | + |
| 176 | +## 🔍 Troubleshooting |
| 177 | + |
| 178 | +### Common Issues |
| 179 | + |
| 180 | +1. **Too Many False Positives** |
| 181 | + |
| 182 | + - Review and clean up the project dictionary |
| 183 | + - Use more specific ignore patterns |
| 184 | + - Consider CSpell ignore comments for edge cases |
| 185 | + |
| 186 | +2. **Missing Technical Terms** |
| 187 | + |
| 188 | + - Add them to `project-words.txt` |
| 189 | + - Keep them lowercase unless proper nouns |
| 190 | + - Sort alphabetically for maintainability |
| 191 | + |
| 192 | +3. **Generated or Binary Content** |
| 193 | + - Add paths to `ignorePaths` in `cspell.json` |
| 194 | + - Use glob patterns to exclude file types |
| 195 | + |
| 196 | +### Getting Help |
| 197 | + |
| 198 | +- Check CSpell suggestions: `cspell --show-suggestions <file>` |
| 199 | +- View CSpell documentation: [https://cspell.org/docs/](https://cspell.org/docs/) |
| 200 | +- Review existing patterns in `cspell.json` |
| 201 | + |
| 202 | +## 🧪 Integration with Development Workflow |
| 203 | + |
| 204 | +### Pre-commit Checks |
| 205 | + |
| 206 | +CSpell is included in the mandatory pre-commit checks: |
| 207 | + |
| 208 | +```bash |
| 209 | +cargo run --bin linter all # Includes CSpell |
| 210 | +``` |
| 211 | + |
| 212 | +### CI/CD Integration |
| 213 | + |
| 214 | +The spell checker runs automatically in CI/CD pipelines as part of the linting process. |
| 215 | + |
| 216 | +### IDE Integration |
| 217 | + |
| 218 | +Consider installing CSpell extensions for your IDE: |
| 219 | + |
| 220 | +- VS Code: "Code Spell Checker" extension |
| 221 | +- Other IDEs: Check CSpell documentation for integration options |
| 222 | + |
| 223 | +## 🎯 Goals |
| 224 | + |
| 225 | +- **Consistency**: Maintain professional spelling across all project content |
| 226 | +- **Quality**: Catch typos early in the development process |
| 227 | +- **Maintainability**: Keep a clean, well-organized project dictionary |
| 228 | +- **Developer Experience**: Provide clear guidance for handling spelling issues |
| 229 | + |
| 230 | +By following these guidelines, we ensure that our codebase maintains high quality while accommodating the technical nature of our domain vocabulary. |
0 commit comments