Skip to content

Speed up codespell:ignore check by skipping the regex in most cases #3721

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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,]*))?"
)
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