Skip to content

Commit 2f2772c

Browse files
Skip subdirectories of hidden directories
Veuillez saisir le message de validation pour vos modifications. Les lignes
1 parent a239c80 commit 2f2772c

File tree

2 files changed

+57
-18
lines changed

2 files changed

+57
-18
lines changed

codespell_lib/_codespell.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,12 @@ def main(*args: str) -> int:
11711171
)
11721172

11731173
# skip (relative) directories
1174-
dirs[:] = [dir_ for dir_ in dirs if not glob_match.match(dir_)]
1174+
dirs[:] = [
1175+
dir_
1176+
for dir_ in dirs
1177+
if not glob_match.match(dir_)
1178+
and not is_hidden(dir_, options.check_hidden)
1179+
]
11751180

11761181
elif not glob_match.match(filename): # skip files
11771182
bad_count += parse_file(

codespell_lib/tests/test_basic.py

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -455,19 +455,33 @@ def test_check_hidden(
455455
capsys: pytest.CaptureFixture[str],
456456
) -> None:
457457
"""Test ignoring of hidden files."""
458-
fname = tmp_path / "test.txt"
459458
# visible file
460-
fname.write_text("abandonned\n")
459+
#
460+
# tmp_path
461+
# └── test.txt
462+
#
463+
fname = tmp_path / "test.txt"
464+
fname.write_text("erorr\n")
461465
assert cs.main(fname) == 1
462466
assert cs.main(tmp_path) == 1
467+
463468
# hidden file
469+
#
470+
# tmp_path
471+
# └── .test.txt
472+
#
464473
hidden_file = tmp_path / ".test.txt"
465474
fname.rename(hidden_file)
466475
assert cs.main(hidden_file) == 0
467476
assert cs.main(tmp_path) == 0
468477
assert cs.main("--check-hidden", hidden_file) == 1
469478
assert cs.main("--check-hidden", tmp_path) == 1
479+
470480
# hidden file with typo in name
481+
#
482+
# tmp_path
483+
# └── .abandonned.txt
484+
#
471485
typo_file = tmp_path / ".abandonned.txt"
472486
hidden_file.rename(typo_file)
473487
assert cs.main(typo_file) == 0
@@ -476,16 +490,28 @@ def test_check_hidden(
476490
assert cs.main("--check-hidden", tmp_path) == 1
477491
assert cs.main("--check-hidden", "--check-filenames", typo_file) == 2
478492
assert cs.main("--check-hidden", "--check-filenames", tmp_path) == 2
493+
479494
# hidden directory
495+
#
496+
# tmp_path
497+
# ├── .abandonned
498+
# │   ├── .abandonned.txt
499+
# │   └── subdir
500+
# │   └── .abandonned.txt
501+
# └── .abandonned.txt
502+
#
480503
assert cs.main(tmp_path) == 0
481504
assert cs.main("--check-hidden", tmp_path) == 1
482505
assert cs.main("--check-hidden", "--check-filenames", tmp_path) == 2
483-
hidden_dir = tmp_path / ".abandonned"
484-
hidden_dir.mkdir()
485-
copyfile(typo_file, hidden_dir / typo_file.name)
506+
hidden = tmp_path / ".abandonned"
507+
hidden.mkdir()
508+
copyfile(typo_file, hidden / typo_file.name)
509+
subdir = hidden / "subdir"
510+
subdir.mkdir()
511+
copyfile(typo_file, subdir / typo_file.name)
486512
assert cs.main(tmp_path) == 0
487-
assert cs.main("--check-hidden", tmp_path) == 2
488-
assert cs.main("--check-hidden", "--check-filenames", tmp_path) == 5
513+
assert cs.main("--check-hidden", tmp_path) == 3
514+
assert cs.main("--check-hidden", "--check-filenames", tmp_path) == 8
489515
# check again with a relative path
490516
try:
491517
rel = op.relpath(tmp_path)
@@ -494,20 +520,28 @@ def test_check_hidden(
494520
pass
495521
else:
496522
assert cs.main(rel) == 0
497-
assert cs.main("--check-hidden", rel) == 2
498-
assert cs.main("--check-hidden", "--check-filenames", rel) == 5
523+
assert cs.main("--check-hidden", rel) == 3
524+
assert cs.main("--check-hidden", "--check-filenames", rel) == 8
525+
499526
# hidden subdirectory
500-
assert cs.main(tmp_path) == 0
501-
assert cs.main("--check-hidden", tmp_path) == 2
502-
assert cs.main("--check-hidden", "--check-filenames", tmp_path) == 5
527+
#
528+
# tmp_path
529+
# ├── .abandonned
530+
# │   ├── .abandonned.txt
531+
# │   └── subdir
532+
# │   └── .abandonned.txt
533+
# ├── .abandonned.txt
534+
# └── subdir
535+
# └── .abandonned
536+
# └── .abandonned.txt
503537
subdir = tmp_path / "subdir"
504538
subdir.mkdir()
505-
hidden_subdir = subdir / ".abandonned"
506-
hidden_subdir.mkdir()
507-
copyfile(typo_file, hidden_subdir / typo_file.name)
539+
hidden = subdir / ".abandonned"
540+
hidden.mkdir()
541+
copyfile(typo_file, hidden / typo_file.name)
508542
assert cs.main(tmp_path) == 0
509-
assert cs.main("--check-hidden", tmp_path) == 3
510-
assert cs.main("--check-hidden", "--check-filenames", tmp_path) == 8
543+
assert cs.main("--check-hidden", tmp_path) == 4
544+
assert cs.main("--check-hidden", "--check-filenames", tmp_path) == 11
511545

512546

513547
def test_case_handling(

0 commit comments

Comments
 (0)