Skip to content
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

Do not allow for a word to start or end with punctuation symbols #3588

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
__version__ as VERSION, # noqa: N812
)

word_regex_def = r"[\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
9 changes: 8 additions & 1 deletion codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def main(
capsys = frame.f_locals["capsys"]
stdout, stderr = capsys.readouterr()
assert code in (EX_OK, EX_USAGE, EX_DATAERR, EX_CONFIG)
# print(f"stderr: {stderr}")
if code == EX_DATAERR: # have some misspellings
code = int(stderr.split("\n")[-2])
elif code == EX_OK and count:
Expand Down Expand Up @@ -117,7 +118,13 @@ def test_basic(
assert cs.main("--builtin", "clear,rare,names,informal", fname) == 4
with fname.open("w") as f: # overwrite the file
f.write("var = 'nwe must check codespell likes escapes nin strings'\n")
assert cs.main(fname) == 1, "checking our string escape test word is bad"
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\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
Loading