Skip to content

Commit 609f269

Browse files
committed
Disallow trailing hyphens or apostrophes (and do not care about single character "words")
1 parent daa5b9c commit 609f269

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

codespell_lib/_codespell.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
__version__ as VERSION, # noqa: N812
5454
)
5555

56-
word_regex_def = r"\w[\w\-'’]*" # noqa: RUF001
56+
# We do not care about single character words, and words should not
57+
# have leading or trailing hyphens or apostrophes.
58+
word_regex_def = r"\w[\w\-'’]*\w" # noqa: RUF001
5759
# While we want to treat characters like ( or " as okay for a starting break,
5860
# these may occur unescaped in URIs, and so we are more restrictive on the
5961
# endpoint. Emails are more restrictive, so the endpoint remains flexible.

codespell_lib/tests/test_basic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ def test_basic(
119119
with fname.open("w") as f: # overwrite the file
120120
f.write("var = 'nwe must check codespell likes escapes nin strings'\n")
121121
assert cs.main(fname) == 2, "checking our string escape test word is bad"
122+
with fname.open("w") as f: # overwrite the file
123+
f.write("fully 'nwe' quoted, or end nwe' quoted\n")
124+
assert cs.main(fname) == 2, "fully or end quoted should be detected"
122125
# the first one is missed because the apostrophe means its not currently
123126
# treated as a word on its own
124127
with fname.open("w") as f: # overwrite the file

0 commit comments

Comments
 (0)