Skip to content

Commit 4fcf562

Browse files
committed
ENH: Generalize handling of contractions like "'d", "'s" or "'th"
Systematically strip the contraction from the error word before performing additional checks.
1 parent 778a6f7 commit 4fcf562

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

codespell.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ def spell_check_comment(
109109
if output_lvl > 1:
110110
print(f"Error: {error_word}")
111111

112+
valid = False
113+
114+
# Check for contractions
115+
for contraction in ["'d", "'s", "'th"]:
116+
if error_word.endswith(contraction):
117+
original_error_word = error_word
118+
error_word = error_word[: -len(contraction)]
119+
if output_lvl > 1:
120+
print(
121+
f"Stripping contraction: {original_error_word} -> {error_word}"
122+
)
123+
if spell_checker.check(error_word):
124+
valid = True
125+
break
126+
127+
if valid:
128+
continue
129+
112130
# Check if the bad word starts with a prefix.
113131
# If so, spell check the word without that prefix.
114132
for pre in prefixes:
@@ -136,12 +154,6 @@ def spell_check_comment(
136154
if len(sub_words) > 1 and spell_check_words(spell_checker, sub_words):
137155
continue
138156

139-
# Check for possessive words
140-
if error_word.endswith("'s"):
141-
wrd = error_word[:-2]
142-
if spell_checker.check(wrd):
143-
continue
144-
145157
if output_lvl > 1:
146158
msg = f"error: '{error_word}', suggestions: {spell_checker.suggest()}"
147159
else:

tests/example.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
//
1919
// Additional dictionary test word:
2020
// TarHeels
21+
//
22+
// Contraction test words:
23+
// With multiple parameters OR'd to compose the flag.
24+
// With node id's.
25+
// With the itemIndex'th where itemIndex is a variable name.
2126

2227
#include <stdio.h>
2328

0 commit comments

Comments
 (0)