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

Skip filename with a path element in the skip list #3198

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
14 changes: 14 additions & 0 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,16 @@ def is_text_file(filename: str) -> bool:
return b"\x00" not in s


def _match_path_parts(filename: str, glob_match: GlobMatch) -> bool:
"""Find if any path part is in the skip list."""
head, tail = os.path.split(filename)
while head:
if tail and glob_match.match(tail):
return True
head, tail = os.path.split(head)
return False


def fix_case(word: str, fixword: str) -> str:
if word == word.capitalize():
return ", ".join(w.strip().capitalize() for w in fixword.split(","))
Expand Down Expand Up @@ -1168,6 +1178,10 @@ def main(*args: str) -> int:
if is_hidden(filename, options.check_hidden):
continue

# skip argument if any piece of the path is in the skip list
DimitriPapadopoulos marked this conversation as resolved.
Show resolved Hide resolved
if _match_path_parts(filename, glob_match):
continue

if os.path.isdir(filename):
for root, dirs, files in os.walk(filename):
if glob_match.match(root): # skip (absolute) directories
Expand Down
1 change: 1 addition & 0 deletions codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ def test_ignore(
assert cs.main("--skip=*ignoredir*", tmp_path) == 1
assert cs.main("--skip=ignoredir", tmp_path) == 1
assert cs.main("--skip=*ignoredir/bad*", tmp_path) == 1
assert cs.main("--skip=ignoredir", subdir) == 0
badjs = tmp_path / "bad.js"
copyfile(badtxt, badjs)
assert cs.main("--skip=*.js", goodtxt, badtxt, badjs) == 1
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ allow-magic-value-types = ["bytes", "int", "str",]
max-args = 12
max-branches = 48
max-returns = 10
max-statements = 111
max-statements = 112
Loading