Skip to content
Open
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
9 changes: 7 additions & 2 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@
uri_regex_def = (
r"(\b(?:https?|[ts]?ftp|file|git|smb)://[^\s]+(?=$|\s)|\b[\w.%+-]+@[\w.-]+\b)"
)
inline_ignore_regex = re.compile(r"[^\w\s]\s*codespell:ignore\b(\s+(?P<words>[\w,]*))?")
codespell_ignore_tag = "codespell:ignore"
inline_ignore_regex = re.compile(
rf"[^\w\s]\s*{codespell_ignore_tag}\b(\s+(?P<words>[\w,]*))?"
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make it an f-string?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that, looks good to me, but needs to be rebased.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it an f-string to extract into a separate variable and substitute it into the regex. I can duplicate it if you prefer that. Do we agree to write it as:

codespell_ignore_tag = "codespell:ignore"
inline_ignore_regex = re.compile(
    r"[^\w\s]\s*codespell:ignore\b(\s+(?P<words>[\w,]*))?"
)

then or did you want something else? :)

USAGE = """
\t%prog [OPTIONS] [file1 file2 ... fileN]
"""
Expand Down Expand Up @@ -951,7 +954,9 @@ def parse_file(
continue

extra_words_to_ignore = set()
match = inline_ignore_regex.search(line)
match = (
inline_ignore_regex.search(line) if codespell_ignore_tag in line else None
)
if match:
extra_words_to_ignore = set(
filter(None, (match.group("words") or "").split(","))
Expand Down
Loading