|
| 1 | +--- |
| 2 | +name: edg-spelling-allowlist |
| 3 | +description: >- |
| 4 | + How the pre-push spell check (edg-check-file-changes, aspell, edgspelling) |
| 5 | + decides what to report, and how to add words to the hierarchical spelling |
| 6 | + allowlist (dev_tools/spelling_allowlist.json). Use when the pre-push hook |
| 7 | + or edg-collect-changes --check reports misspelled words, when choosing |
| 8 | + where a new allowed word belongs, or when editing the allowlist file. |
| 9 | +--- |
| 10 | + |
| 11 | +# Spell check and the spelling allowlist |
| 12 | + |
| 13 | +## How the check works |
| 14 | + |
| 15 | +The pre-push hook (`.git-hooks/pre-push.py`) runs |
| 16 | +`dev_tools/bin/edg-check-file-changes` on every changed file, through |
| 17 | +`edg-exec` when docker is preferred. Its spelling pass: |
| 18 | + |
| 19 | +- Runs `aspell list` on the text. For code files (`.c`, `.cpp`, `.h`, |
| 20 | + `.hpp`) only the comments are checked (extracted with `get-comments`). |
| 21 | + Other files are checked whole. |
| 22 | +- First splits identifiers into words (`edgspelling.preprocess`): `fooBar` |
| 23 | + becomes `foo Bar`. Underscores already split words, so `foo_bar` is |
| 24 | + checked as `foo` and `bar`. |
| 25 | +- Reports only words that are **new** relative to the old version of the |
| 26 | + file, minus the allowlist words for that file's path. |
| 27 | +- For pending Changes entries (`*/pending_changes/*.txt`), also accepts |
| 28 | + the entry's `//allowed_words:` directives and any word already in the |
| 29 | + target `Changes` file (see skill **edg-changes-example**). CI runs the |
| 30 | + same check with `edg-collect-changes --check`. |
| 31 | + |
| 32 | +The hook skips some paths entirely (`EXCLUDES_PATH_PREFIXES` in |
| 33 | +`.git-hooks/pre-push.py`), including `AGENTS.md`, `.agents/`, and the |
| 34 | +allowlist itself. |
| 35 | + |
| 36 | +## The allowlist file |
| 37 | + |
| 38 | +`dev_tools/spelling_allowlist.json` is a tree of nodes. Each node may have: |
| 39 | + |
| 40 | +| Key | Meaning | |
| 41 | +| --- | --- | |
| 42 | +| `words` | Sorted lowercase words, allowed in any capitalization | |
| 43 | +| `names` | Sorted words allowed only with exactly this capitalization | |
| 44 | +| `paths` | Object mapping one path component (directory or file name) to a child node | |
| 45 | + |
| 46 | +A file's allowed words are the union of the nodes on the way down to it, so a |
| 47 | +word in the root node is allowed everywhere. The format is documented in |
| 48 | +`dev_tools/pylibs/edgspelling/__init__.py`. |
| 49 | + |
| 50 | +Rules that `edgspelling.Allowlist` enforces when the file loads (a bad |
| 51 | +file makes the check refuse to run and fails `ShippedAllowlistTests` in CI): |
| 52 | + |
| 53 | +- Each list is sorted by code point and has no duplicates. |
| 54 | +- `words` entries are lowercase. Use `names` when the capitalization must |
| 55 | + match (proper nouns like `EDG` or `Coverity`). |
| 56 | +- Only `words`, `names`, and `paths` keys are allowed. |
| 57 | +- Each entry is one word. `foo_bar` or `fooBar` would never match, because |
| 58 | + identifiers are split before lookup. Add the parts instead. |
| 59 | + |
| 60 | +## Choosing where a word goes |
| 61 | + |
| 62 | +Put a word in the **narrowest node** that covers the places it's used |
| 63 | +often (see "Prompting is the default" below): |
| 64 | + |
| 65 | +- **Root:** terms used across the project (C++ terminology, `src`, `utf`). |
| 66 | +- **A directory node** (`src`, `dev_tools`, `dev_tools/pylibs/edgtest`, |
| 67 | + `doc/source`, …): jargon used only there. Common Python names like |
| 68 | + `isinstance` and `pathlib`, and the pylib package names (`edgutil`, …), |
| 69 | + live in `dev_tools`. The rare uses elsewhere (`dev-init.py`, |
| 70 | + `.git-hooks/`, `doc/source/conf.py`) are left to prompt. |
| 71 | + |
| 72 | +A word used in only one file almost never earns an entry. The check |
| 73 | +reports only words that are new to a file, so the entry would save a prompt |
| 74 | +only when the word shows up in a second file. A word used only in a |
| 75 | +`Changes` file never needs one, because pending entries already accept |
| 76 | +every word in their target `Changes` file. |
| 77 | +- **A file node:** a one-off term in a single file. |
| 78 | + |
| 79 | +### Prompting is the default |
| 80 | + |
| 81 | +Each allowed word is a blind spot: a typo that happens to match it is never |
| 82 | +reported anywhere the entry applies. A broader node makes the blind spot |
| 83 | +bigger. Being prompted again costs little, because the check reports only |
| 84 | +words that are new to a file. Weigh the two: |
| 85 | + |
| 86 | +- Prefer leaving a word out and letting people be prompted. Add it only when |
| 87 | + people would otherwise be prompted for it very often (for example, a term |
| 88 | + used constantly across a directory or the project). |
| 89 | +- When a word does earn an entry, choose the narrowest node that stops the |
| 90 | + frequent prompts, even if rare uses elsewhere still prompt. For example, |
| 91 | + the Python names are in `dev_tools` rather than at the root. |
| 92 | +- Be most careful with short words and words that are one letter away from |
| 93 | + a common English word (`len`, `str`, `dir`). They're the likeliest to hide |
| 94 | + a real typo. |
| 95 | + |
| 96 | +Don't add a real misspelling. Fix the text. For a Changes entry, prefer an |
| 97 | +`//allowed_words:` directive over a new allowlist word unless the term will |
| 98 | +recur. |
| 99 | + |
| 100 | +## Editing the file |
| 101 | + |
| 102 | +Keep the existing formatting (one-space JSON indent, UTF-8, non-ASCII kept as |
| 103 | +is). A Python round trip keeps it exact and keeps the lists sorted: |
| 104 | + |
| 105 | +```python |
| 106 | +import json, pathlib |
| 107 | +path = pathlib.Path('dev_tools/spelling_allowlist.json') |
| 108 | +tree = json.loads(path.read_text(encoding = 'utf-8')) |
| 109 | +tree['words'] = sorted(set(tree['words']) | {'newword'}) |
| 110 | +# For a nested node: tree['paths']['src']['words'] = ... |
| 111 | +path.write_text( |
| 112 | + json.dumps(tree, indent = 1, ensure_ascii = False) + '\n', |
| 113 | + encoding = 'utf-8' |
| 114 | +) |
| 115 | +``` |
| 116 | + |
| 117 | +Then check that the file still loads, and run the tests: |
| 118 | + |
| 119 | +```sh |
| 120 | +PYTHONPATH=dev_tools/pylibs python3 -c 'import edgspelling; edgspelling.Allowlist()' |
| 121 | +PYTHONPATH=dev_tools/pylibs python3 -m unittest discover -s dev_tools/tests \ |
| 122 | + -p 'test_edg_check_file_changes.py' |
| 123 | +``` |
| 124 | + |
| 125 | +To see what aspell rejects in some text: |
| 126 | +`printf '%s\n' word1 word2 | aspell list`. |
0 commit comments