From 1dcd6756354f6586dcfc721dc8a3b843e77f3b09 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 19 Oct 2022 13:26:47 +0200 Subject: [PATCH] Skip subdirectories of hidden directories --- codespell_lib/_codespell.py | 7 ++++++- codespell_lib/tests/test_basic.py | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 49a62a3996a..d64cc733b89 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -1171,7 +1171,12 @@ def main(*args: str) -> int: ) # skip (relative) directories - dirs[:] = [dir_ for dir_ in dirs if not glob_match.match(dir_)] + dirs[:] = [ + dir_ + for dir_ in dirs + if not glob_match.match(dir_) + and not is_hidden(dir_, options.check_hidden) + ] elif not glob_match.match(filename): # skip files bad_count += parse_file( diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index f40a7ae04d4..cabbab9ed02 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -483,6 +483,9 @@ def test_check_hidden( hidden_dir = tmp_path / ".abandonned" hidden_dir.mkdir() copyfile(typo_file, hidden_dir / typo_file.name) + hidden_subdir = hidden_dir / "subdir" + hidden_subdir.mkdir() + copyfile(typo_file, hidden_subdir / typo_file.name) assert cs.main(tmp_path) == 0 assert cs.main("--check-hidden", tmp_path) == 2 assert cs.main("--check-hidden", "--check-filenames", tmp_path) == 5