Commit 84a2279
chore: catch doubled words in pre-commit (#404)
* chore: catch doubled words in pre-commit
A mechanical rename left "a label label" in a docstring on a branch this week.
Tests, `mypy --strict`, ruff and an AST comparison all passed over it: the AST
check strips docstrings before comparing, so it is silent by construction about
the text a rename most easily breaks. Only reading the diff found it.
A doubled word is the mechanical signature of that mistake -- a regex that
rewrites one word of a phrase leaves its neighbour standing -- and it is
cheap to check.
Measured before adding, since a gate that mostly cries wolf is worse than none:
across 168 tracked text files the pattern reports **zero** false positives.
Restricting the word to `[A-Za-z]+` is what buys that; `\w+` also matches RDB
column types like `10n 10n`.
Its first real run found a typo in a user-facing demo notebook -- "Filters on
the the associated monitoring location" -- which had been shipped and read past.
The one other hit was a genuinely clumsy sentence in a test docstring ("Which
variable that is is platform-specific"), reworded rather than excluded, so the
hook needs no exclusion list beyond `tests/data/`, which the other prose hooks
already skip because it holds byte-exact API captures.
Line-scoped on purpose. Matching across newlines too was tried and rejected: it
finds nothing real and reports a Markdown heading followed by its own first
word, or `return df` above `df` -- 19 such reports against 0 real ones.
Confirmed it can fail. Seeding a doubled word makes the hook exit 1 and name
the file and line; the check was run against that seed before being kept.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAEQqs7XzQHGQQi2KakuXD
* Update .pre-commit-config.yaml
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 9b519e2 commit 84a2279
3 files changed
Lines changed: 13 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
23 | 32 | | |
24 | 33 | | |
25 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1025 | 1025 | | |
1026 | 1026 | | |
1027 | 1027 | | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
1031 | 1031 | | |
1032 | 1032 | | |
1033 | 1033 | | |
| |||
0 commit comments