Skip to content

Handle words surrounded by single quotes #3596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,13 +759,20 @@
colors: TermColors,
) -> Tuple[bool, str]:
wrongword = match.group()
match_start = match.start()
match_end = match.end()
# Detect single quotes, i.e. 'wrongword'->wrongword
if wrongword[0] == "'" and wrongword[-1] == "'":
wrongword = wrongword[1:-1]
match_start += 1
match_end -= 1

Check warning on line 768 in codespell_lib/_codespell.py

View check run for this annotation

Codecov / codecov/patch

codespell_lib/_codespell.py#L766-L768

Added lines #L766 - L768 were not covered by tests
if interactivity <= 0:
return misspelling.fix, fix_case(wrongword, misspelling.data)

line_ui = (
f"{line[:match.start()]}"
f"{line[:match_start]}"
f"{colors.WWORD}{wrongword}{colors.DISABLE}"
f"{line[match.end():]}"
f"{line[match_end:]}"
)

if misspelling.fix and interactivity & 1:
Expand Down Expand Up @@ -980,14 +987,19 @@
)
for match in check_matches:
word = match.group()
match_start = match.start()
# Detect single quotes, i.e. 'word'->word
if word[0] == "'" and word[-1] == "'":
word = word[1:-1]
match_start += 1
if word in ignore_words_cased:
continue
lword = word.lower()
if lword in misspellings and lword not in extra_words_to_ignore:
# Sometimes we find a 'misspelling' which is actually a valid word
# preceded by a string escape sequence. Ignore such cases as
# they're usually false alarms; see issue #17 among others.
char_before_idx = match.start() - 1
char_before_idx = match_start - 1
if (
char_before_idx >= 0
and line[char_before_idx] == "\\"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ allow-magic-value-types = ["bytes", "int", "str",]
max-args = 13
max-branches = 48
max-returns = 12
max-statements = 119
max-statements = 123