Skip to content

Commit

Permalink
Interpret --skip arguments as relative paths
Browse files Browse the repository at this point in the history
The --skip arguments are interpreted as paths relative to the
directories to check (the "file" arguments passed to codespell).

The benefit is that "codespell ." and "codespell $PWD" behave
the same, you just pass relative paths to --skip. No more adding
"./" to directory patterns.
  • Loading branch information
DimitriPapadopoulos committed Sep 10, 2021
1 parent 1af1d32 commit d4ead50
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,8 @@ def main(*args):

if os.path.isdir(filename):
for root, dirs, files in os.walk(filename):
if glob_match.match(root): # skip (absolute) directories
rel_root = os.path.relpath(root, filename)
if glob_match.match(rel_root): # skip directory (rel. path)
del dirs[:]
continue
if is_hidden(root, options.check_hidden): # dir itself hidden
Expand All @@ -884,20 +885,21 @@ def main(*args):
# ignore hidden files in directories
if is_hidden(file_, options.check_hidden):
continue
if glob_match.match(file_): # skip files
if glob_match.match(file_): # skip file (base name)
continue
fname = os.path.join(root, file_)
if glob_match.match(fname): # skip paths
rel_path = os.path.join(rel_root, file_)
if glob_match.match(rel_path): # skip file (rel. path)
continue
abs_path = os.path.join(root, file_)
bad_count += parse_file(
fname, colors, summary, misspellings, exclude_lines,
abs_path, colors, summary, misspellings, exclude_lines,
file_opener, word_regex, ignore_word_regex, uri_regex,
uri_ignore_words, context, options)

# skip (relative) directories
# skip directory (base name)
dirs[:] = [dir_ for dir_ in dirs if not glob_match.match(dir_)]

elif not glob_match.match(filename): # skip files
elif not glob_match.match(filename): # skip file
bad_count += parse_file(
filename, colors, summary, misspellings, exclude_lines,
file_opener, word_regex, ignore_word_regex, uri_regex,
Expand Down

0 comments on commit d4ead50

Please sign in to comment.