Skip to content

Commit

Permalink
Use pre-commit to sort the dictionaries
Browse files Browse the repository at this point in the history
This changes the sort order of specific characters (like `"_"`)
but is cross-platform and can be fixed by pre-commit.ci.

Closes #2689
  • Loading branch information
kurtmckee committed Jul 27, 2023
1 parent c6ef754 commit 3cb95ab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ repos:
- id: fix-byte-order-marker
- id: check-case-conflict
- id: check-toml
- id: file-contents-sorter
files: dictionary.*\.txt$
args: [--ignore-case]
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.32.0
hooks:
Expand Down
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ codespell.1: codespell.1.include Makefile

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

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

trim-dictionaries:
@for dictionary in ${DICTIONARIES}; do \
Expand Down
14 changes: 7 additions & 7 deletions codespell_lib/data/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
3rt->3rd
3st->3rd
4rd->4th
__attribyte__->__attribute__
__cpluspus->__cplusplus
__cpusplus->__cplusplus
a-diaerers->a-diaereses
aaccess->access
aaccessibility->accessibility
Expand Down Expand Up @@ -8230,9 +8233,9 @@ cllouds->clouds
cloack->cloak
cloacks->cloaks
cloberring->clobbering
clock_getttime->clock_gettime
clocksourc->clocksource
clockwíse->clockwise
clock_getttime->clock_gettime
clodes->closed, clothes,
cloding->closing
cloes->close
Expand Down Expand Up @@ -11247,8 +11250,8 @@ cought->caught, cough, fought,
coul->could
could'nt->couldn't
could't->couldn't
couldent->couldn't
coulden`t->couldn't
couldent->couldn't
couldn->could, couldn't,
couldn;t->couldn't
couldnt'->couldn't
Expand Down Expand Up @@ -31326,6 +31329,7 @@ phsyically->physically
phsyics->physics
phtread->pthread
phtreads->pthreads
phy_interace->phy_interface
phyiscal->physical
phyiscally->physically
phyiscs->physics
Expand All @@ -31352,7 +31356,6 @@ physisions->physicians
physisist->physicist
phython->python
phyton->python
phy_interace->phy_interface
piar->pair, pier, pliers,
piars->pairs, piers, pliers,
piblisher->publisher
Expand Down Expand Up @@ -47125,8 +47128,8 @@ woudl->would
woudn't->wouldn't
would'nt->wouldn't
would't->wouldn't
wouldent->wouldn't
woulden`t->wouldn't
wouldent->wouldn't
wouldn;t->wouldn't
wouldnt'->wouldn't
wouldnt->wouldn't
Expand Down Expand Up @@ -47370,9 +47373,6 @@ zukeeni->zucchini
zuser->user
zylophone->xylophone
zylophones->xylophones
__attribyte__->__attribute__
__cpluspus->__cplusplus
__cpusplus->__cplusplus
évaluate->evaluate
сontain->contain
сontained->contained
Expand Down
15 changes: 15 additions & 0 deletions codespell_lib/tests/test_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ def test_dictionary_formatting(
raise AssertionError("\n" + "\n".join(errors))


@fname_params
def test_dictionary_sorting(
fname: str,
in_aspell: Tuple[bool, bool],
in_dictionary: Tuple[Iterable[str], Iterable[str]],
) -> None:
previous_line = None
with open(fname) as file:
for current_line in file:
current_line = current_line.strip().lower()
if previous_line is not None:
assert previous_line < current_line, f"{fname} is not sorted"
previous_line = current_line


def _check_aspell(
phrase: str,
msg: str,
Expand Down

0 comments on commit 3cb95ab

Please sign in to comment.