Skip to content

Commit 212f0d3

Browse files
committed
Use pre-commit to sort the dictionaries
This changes the sort order of specific characters (like `"_"`) but is cross-platform and can be fixed by pre-commit.ci. Closes #2689
1 parent c6ef754 commit 212f0d3

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ repos:
4646
- id: fix-byte-order-marker
4747
- id: check-case-conflict
4848
- id: check-toml
49+
- id: file-contents-sorter
50+
files: dictionary.*\.txt$
51+
args: [--ignore-case]
4952
- repo: https://github.com/adrienverge/yamllint.git
5053
rev: v1.32.0
5154
hooks:

Makefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ codespell.1: codespell.1.include Makefile
1414

1515
check-dictionaries:
1616
@for dictionary in ${DICTIONARIES}; do \
17-
if ! LC_ALL=C sort ${SORT_ARGS} -c $$dictionary; then \
18-
echo "Dictionary $$dictionary not sorted. Sort with 'make sort-dictionaries'"; \
19-
exit 1; \
20-
fi; \
2117
if grep -E -n "^\s*$$|\s$$|^\s" $$dictionary; then \
2218
echo "Dictionary $$dictionary contains leading/trailing whitespace and/or blank lines. Trim with 'make trim-dictionaries'"; \
2319
exit 1; \
@@ -31,9 +27,7 @@ check-dictionaries:
3127
fi
3228

3329
sort-dictionaries:
34-
@for dictionary in ${DICTIONARIES}; do \
35-
LC_ALL=C sort ${SORT_ARGS} -u -o $$dictionary $$dictionary; \
36-
done
30+
pre-commit run --all-files file-contents-sorter
3731

3832
trim-dictionaries:
3933
@for dictionary in ${DICTIONARIES}; do \

codespell_lib/data/dictionary.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
3rt->3rd
66
3st->3rd
77
4rd->4th
8+
__attribyte__->__attribute__
9+
__cpluspus->__cplusplus
10+
__cpusplus->__cplusplus
811
a-diaerers->a-diaereses
912
aaccess->access
1013
aaccessibility->accessibility
@@ -8230,9 +8233,9 @@ cllouds->clouds
82308233
cloack->cloak
82318234
cloacks->cloaks
82328235
cloberring->clobbering
8236+
clock_getttime->clock_gettime
82338237
clocksourc->clocksource
82348238
clockwíse->clockwise
8235-
clock_getttime->clock_gettime
82368239
clodes->closed, clothes,
82378240
cloding->closing
82388241
cloes->close
@@ -11247,8 +11250,8 @@ cought->caught, cough, fought,
1124711250
coul->could
1124811251
could'nt->couldn't
1124911252
could't->couldn't
11250-
couldent->couldn't
1125111253
coulden`t->couldn't
11254+
couldent->couldn't
1125211255
couldn->could, couldn't,
1125311256
couldn;t->couldn't
1125411257
couldnt'->couldn't
@@ -31326,6 +31329,7 @@ phsyically->physically
3132631329
phsyics->physics
3132731330
phtread->pthread
3132831331
phtreads->pthreads
31332+
phy_interace->phy_interface
3132931333
phyiscal->physical
3133031334
phyiscally->physically
3133131335
phyiscs->physics
@@ -31352,7 +31356,6 @@ physisions->physicians
3135231356
physisist->physicist
3135331357
phython->python
3135431358
phyton->python
31355-
phy_interace->phy_interface
3135631359
piar->pair, pier, pliers,
3135731360
piars->pairs, piers, pliers,
3135831361
piblisher->publisher
@@ -47125,8 +47128,8 @@ woudl->would
4712547128
woudn't->wouldn't
4712647129
would'nt->wouldn't
4712747130
would't->wouldn't
47128-
wouldent->wouldn't
4712947131
woulden`t->wouldn't
47132+
wouldent->wouldn't
4713047133
wouldn;t->wouldn't
4713147134
wouldnt'->wouldn't
4713247135
wouldnt->wouldn't
@@ -47370,9 +47373,6 @@ zukeeni->zucchini
4737047373
zuser->user
4737147374
zylophone->xylophone
4737247375
zylophones->xylophones
47373-
__attribyte__->__attribute__
47374-
__cpluspus->__cplusplus
47375-
__cpusplus->__cplusplus
4737647376
évaluate->evaluate
4737747377
сontain->contain
4737847378
сontained->contained

codespell_lib/tests/test_dictionary.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ def test_dictionary_formatting(
7777
raise AssertionError("\n" + "\n".join(errors))
7878

7979

80+
@fname_params
81+
def test_dictionary_sorting(
82+
fname: str,
83+
in_aspell: Tuple[bool, bool],
84+
in_dictionary: Tuple[Iterable[str], Iterable[str]],
85+
) -> None:
86+
previous_line = None
87+
with open(fname, encoding="utf-8") as file:
88+
for current_line in file:
89+
current_line = current_line.strip().lower()
90+
if previous_line is not None:
91+
assert previous_line < current_line, f"{fname} is not sorted"
92+
previous_line = current_line
93+
94+
8095
def _check_aspell(
8196
phrase: str,
8297
msg: str,

0 commit comments

Comments
 (0)