Skip to content

Commit

Permalink
RF: make it explicit to allow words in single quotes and allow traili…
Browse files Browse the repository at this point in the history
…ng quote
  • Loading branch information
yarikoptic committed Nov 22, 2024
1 parent 609f269 commit 7282837
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
__version__ as VERSION, # noqa: N812
)

# We do not care about single character words, and words should not
# have leading or trailing hyphens or apostrophes.
word_regex_def = r"\w[\w\-'’]*\w" # noqa: RUF001
# Words could be surrounded in quotes, so we allow for that, but no nested quotes.
# Cannot have leading but can have trailing hyphens or apostrophes.
word_regex_def = r"(?<=')[\w\-’]+(?=')|(?<=’)[\w\-']+(?=’)|\w[\w\-'’]*" # noqa: RUF001
# While we want to treat characters like ( or " as okay for a starting break,
# these may occur unescaped in URIs, and so we are more restrictive on the
# endpoint. Emails are more restrictive, so the endpoint remains flexible.
Expand Down
7 changes: 5 additions & 2 deletions codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ def test_basic(
f.write("var = 'nwe must check codespell likes escapes nin strings'\n")
assert cs.main(fname) == 2, "checking our string escape test word is bad"
with fname.open("w") as f: # overwrite the file
f.write("fully 'nwe' quoted, or end nwe' quoted\n")
assert cs.main(fname) == 2, "fully or end quoted should be detected"
f.write("fully 'nwe' quoted\n")
assert cs.main(fname) == 1, "fully quoted"
with fname.open("w") as f: # overwrite the file
f.write("only end nwe' quoted\n")
assert cs.main(fname) == 0, "only end quoted should be ok since we have werent'"
# the first one is missed because the apostrophe means its not currently
# treated as a word on its own
with fname.open("w") as f: # overwrite the file
Expand Down

0 comments on commit 7282837

Please sign in to comment.