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

How can I skip globbing of filenames in skip? How can I skip files with [ ] characters in its name? #2142

Closed
matkoniecz opened this issue Nov 11, 2021 · 2 comments
Labels

Comments

@matkoniecz
Copy link
Contributor

matkoniecz commented Nov 11, 2021

-S SKIP, --skip SKIP comma-separated list of files to skip. It accepts globs as well.

As expected, without --skip all files gets typos detected

mateusz@grima:~/Desktop/tmp$ codespell
./example file with actual [weird signs in it]:1: speling ==> spelling
./simple:1: speling ==> spelling
./expected:1: speling ==> spelling

Skipping fails for one with [ ] as it gets globbed:

mateusz@grima:~/Desktop/tmp$ codespell --skip "example file with actual [weird signs in it]" --skip simple
./example file with actual [weird signs in it]:1: speling ==> spelling
./expected:1: speling ==> spelling

Yes, it is an actual filename

And yes, it happened with already existing files. It is sadly not some contrived setup.


Workaround

one may use

codespell --skip "example file with actual [weird signs in it]" --skip simple |grep -Fv "example file with actual [weird signs in it]:1: speling ==> spelling"

F is --fixed-strings PATTERNS are strings

This gives expected

./expected:1: speling ==> spelling

(note that in codespell both fixes strings and globs may be used in one command)


Bonus crash

Also, as result codespell --skip "example file with actual [weird signs in it and b-a]" goes down with

Traceback (most recent call last):
  File "/home/mateusz/.local/bin/codespell", line 8, in <module>
    sys.exit(_script_main())
  File "/home/mateusz/.local/lib/python3.8/site-packages/codespell_lib/_codespell.py", line 748, in _script_main
    return main(*sys.argv[1:])
  File "/home/mateusz/.local/lib/python3.8/site-packages/codespell_lib/_codespell.py", line 876, in main
    if glob_match.match(root):  # skip (absolute) directories
  File "/home/mateusz/.local/lib/python3.8/site-packages/codespell_lib/_codespell.py", line 108, in match
    if fnmatch.fnmatch(filename, p):
  File "/usr/lib/python3.8/fnmatch.py", line 36, in fnmatch
    return fnmatchcase(name, pat)
  File "/usr/lib/python3.8/fnmatch.py", line 70, in fnmatchcase
    match = _compile_pattern(pat)
  File "/usr/lib/python3.8/fnmatch.py", line 46, in _compile_pattern
    return re.compile(res).match
  File "/usr/lib/python3.8/re.py", line 252, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python3.8/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib/python3.8/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib/python3.8/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/lib/python3.8/sre_parse.py", line 834, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
  File "/usr/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/lib/python3.8/sre_parse.py", line 598, in _parse
    raise source.error(msg, len(this) + 1 + len(that))
re.error: bad character range b-a at position 56
@matkoniecz matkoniecz changed the title How can I skip flobbing of filenames in skip? How can I skip files with [ - ] characters in its name? How can I skip globbing of filenames in skip? How can I skip files with [ - ] characters in its name? Nov 11, 2021
@matkoniecz matkoniecz changed the title How can I skip globbing of filenames in skip? How can I skip files with [ - ] characters in its name? How can I skip globbing of filenames in skip? How can I skip files with [ ] characters in its name? Nov 11, 2021
@matkoniecz
Copy link
Contributor Author

Note: I am also fine with solution "use overcomplicated grep workarounds for your overcomplicated file names" if there is no viable and real way to fix it given various limitations, including "we have 74 pull requests and 110 issues more important than this".

@peternewman
Copy link
Collaborator

python3 -m codespell_lib test --skip simple --skip "example file with actual [[]weird signs in it[]]"
test/expected:1: speling ==> spelling

Care of:
https://stackoverflow.com/questions/2595119/glob-and-bracket-characters

The character class thing is a genuine bug though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants