Skip to content

Commit 778a6f7

Browse files
authored
Merge pull request #38 from jcfr/introduce-error_word-var
STYLE: Introduce "error_word" ivar
2 parents fd10ef9 + f3f761d commit 778a6f7

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

codespell.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,46 +104,48 @@ def spell_check_comment(
104104
spell_checker.set_text(c.text())
105105

106106
for error in spell_checker:
107+
error_word = error.word
108+
107109
if output_lvl > 1:
108-
print(f"Error: {error.word}")
110+
print(f"Error: {error_word}")
109111

110112
# Check if the bad word starts with a prefix.
111113
# If so, spell check the word without that prefix.
112114
for pre in prefixes:
113-
if error.word.startswith(pre):
115+
if error_word.startswith(pre):
114116
# check if the word is only the prefix
115-
if len(pre) == len(error.word):
117+
if len(pre) == len(error_word):
116118
if output_lvl > 1:
117119
print(f"Prefix '{pre}' matches word")
118120
break
119121

120122
# remove the prefix
121-
wrd = error.word[len(pre) :]
123+
wrd = error_word[len(pre) :]
122124
if output_lvl > 1:
123-
print(f"Trying without '{pre}' prefix: {error.word} -> {wrd}")
125+
print(f"Trying without '{pre}' prefix: {error_word} -> {wrd}")
124126
try:
125127
if spell_checker.check(wrd):
126128
break
127129
except BaseException:
128-
print(f"Caught an exception for word {error.word} {wrd}")
130+
print(f"Caught an exception for word {error_word} {wrd}")
129131

130132
# Try splitting camel case words and checking each sub-word
131133
if output_lvl > 1:
132-
print(f"Trying splitting camel case word: {error.word}")
133-
sub_words = splitCamelCase(error.word)
134+
print(f"Trying splitting camel case word: {error_word}")
135+
sub_words = splitCamelCase(error_word)
134136
if len(sub_words) > 1 and spell_check_words(spell_checker, sub_words):
135137
continue
136138

137139
# Check for possessive words
138-
if error.word.endswith("'s"):
139-
wrd = error.word[:-2]
140+
if error_word.endswith("'s"):
141+
wrd = error_word[:-2]
140142
if spell_checker.check(wrd):
141143
continue
142144

143145
if output_lvl > 1:
144-
msg = f"error: '{error.word}', suggestions: {spell_checker.suggest()}"
146+
msg = f"error: '{error_word}', suggestions: {spell_checker.suggest()}"
145147
else:
146-
msg = error.word
148+
msg = error_word
147149
mistakes.append(msg)
148150

149151
return mistakes

0 commit comments

Comments
 (0)