Skip to content

Commit 84a2279

Browse files
thodson-usgsclaude
andauthored
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

File tree

‎.pre-commit-config.yaml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ repos:
2020
- id: check-yaml
2121
- id: debug-statements
2222

23+
- repo: local
24+
hooks:
25+
- id: doubled-word
26+
name: doubled word
27+
language: pygrep
28+
entry: \b([A-Za-z]+)[ \t]+\1\b
29+
types: [text]
30+
exclude: ^tests/data/
31+
2332
- repo: https://github.com/astral-sh/ruff-pre-commit
2433
rev: v0.16.1
2534
hooks:

‎demos/hydroshare/USGS_WaterData_Samples_Examples.ipynb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
" A user supplied characteristic name describing one or more results.\n",
101101
" Use `get_codes(code_service=\"observedproperty\")` for all possible inputs.\n",
102102
"* **boundingBox**: list of four floats, optional\n",
103-
" Filters on the the associated monitoring location's point location\n",
103+
" Filters on the associated monitoring location's point location\n",
104104
" by checking if it is located within the specified geographic area. \n",
105105
" The logic is inclusive, i.e. it will include locations that overlap\n",
106106
" with the edge of the bounding box. Values are separated by commas,\n",

‎tests/configuration_test.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,9 +1025,9 @@ def test_broken_config_does_not_break_unrelated_services(config_file):
10251025
def test_default_config_path_follows_a_changed_home(tmp_path, monkeypatch):
10261026
"""The default path derives from the home variable, so the memo watches it.
10271027
1028-
Which variable that is is platform-specific: ``ntpath.expanduser`` reads
1029-
``USERPROFILE`` and ignores ``HOME``, so setting ``HOME`` on Windows moves
1030-
nothing and this asserted against the runner's real home directory.
1028+
Which variable that is depends on the platform: ``ntpath.expanduser``
1029+
reads ``USERPROFILE`` and ignores ``HOME``, so setting ``HOME`` on Windows
1030+
moves nothing and this asserted against the runner's real home directory.
10311031
"""
10321032
home_var = "USERPROFILE" if os.name == "nt" else "HOME"
10331033
monkeypatch.delenv(configuration.CONFIG_PATH_ENV, raising=False)

0 commit comments

Comments
 (0)