Skip to content
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
12 changes: 9 additions & 3 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,11 @@ def convert_arg_line_to_args(self, arg_line: str) -> list[str]:
"--check-hidden",
action="store_true",
default=False,
help='check hidden files and directories (those starting with ".") as well.',
help=(
'check hidden files and directories (those starting with ".") as '
"well. Hidden files named explicitly on the command line are always "
"checked."
),
)
parser.add_argument(
"-A",
Expand Down Expand Up @@ -1528,8 +1532,10 @@ def main(*args: str) -> int:

bad_count = 0
for filename in sorted(options.files):
# ignore hidden files
if is_hidden(filename, options.check_hidden):
# A hidden path named explicitly on the command line is checked even
# without --check-hidden. Directories still honor --check-hidden so that
# recursing into them does not pull in hidden contents unexpectedly.
if is_hidden(filename, options.check_hidden) and os.path.isdir(filename):
continue

if os.path.isdir(filename):
Expand Down
11 changes: 9 additions & 2 deletions codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,9 @@ def test_check_hidden(
#
hidden_file = tmp_path / ".test.txt"
fname.rename(hidden_file)
assert cs.main(hidden_file) == 0
# A hidden file named explicitly is checked even without --check-hidden,
# but the same file reached by recursing a directory is still skipped.
assert cs.main(hidden_file) == 1
assert cs.main(tmp_path) == 0
assert cs.main("--check-hidden", hidden_file) == 1
assert cs.main("--check-hidden", tmp_path) == 1
Expand All @@ -786,7 +788,8 @@ def test_check_hidden(
#
typo_file = tmp_path / ".abandonned.txt"
hidden_file.rename(typo_file)
assert cs.main(typo_file) == 0
assert cs.main(typo_file) == 1
assert cs.main("--check-filenames", typo_file) == 2
assert cs.main(tmp_path) == 0
assert cs.main("--check-hidden", typo_file) == 1
assert cs.main("--check-hidden", tmp_path) == 1
Expand All @@ -811,6 +814,10 @@ def test_check_hidden(
subdir = hidden / "subdir"
subdir.mkdir()
copyfile(typo_file, subdir / typo_file.name)
# An explicitly named hidden directory is still skipped without
# --check-hidden, since scanning its contents is a recursive scan.
assert cs.main(hidden) == 0
assert cs.main("--check-hidden", hidden) == 2
assert cs.main(tmp_path) == 0
assert cs.main("--check-hidden", tmp_path) == 3
assert cs.main("--check-hidden", "--check-filenames", tmp_path) == 8
Expand Down