PyCQA / pydocstyle

docstring style checker
http://pydocstyle.org
MIT License
1.11k stars 189 forks source link

Fix match option to only consider basename when given a path argument #550

Closed oczkoisse closed 2 years ago

oczkoisse commented 3 years ago

Fixes #549.

This uses os.path.basename before trying to match against the pattern set in --match option. This way, even if full paths to files are passed to pydocstyle (by VSCode, for example), only filename part of the path will be matched with the set pattern, thereby eliminating accidental matches with the path. This is also more consistent with how --match is documented previously.

Please make sure to check for the following items:

sambhav commented 2 years ago

@oczkoisse 👋 Thank you so much for the fix and sorry for the delay in reviewing the PR. After my latest commit e5880d5 (#550) in order to preserve b/w compat for match patterns like (src\/*\.py) i.e patterns that match a full path for eg. - it seems like it breaks the test you added for the negative regex matches.

I am in a difficult conundrum with this since one way breaks b/w compat for nested match paths and the other causes issues with negative match directives.

Re-thinking this PR in the context of #529 - I think it might be better for me to revert my latest commit and merge #529 to have proper support for nested dir paths.

oczkoisse commented 2 years ago

Thanks @samj1912 for taking the time to review this PR. I think #529 is a good way to provide an alternative to people who rely on --match to match against nested paths.