Skip to content

Commit

Permalink
ignore-patterns match against the full path instead of basename
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernard Nauwelaerts committed Nov 21, 2019
1 parent 722de48 commit d574e15
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Expand Up @@ -352,3 +352,5 @@ contributors:
* Bastien Vallet: contributor

* Pek Chhan: contributor

* Bernard Nauwelaerts: contributor
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -7,6 +7,10 @@ What's New in Pylint 2.5.0?

Release date: TBA

* Fixed ``ignore-patterns`` behaviour. Defined patterns are matched against full file path instead of file base name.

Close #2541

* Add a --fail-under <score> flag, also configurable in a .pylintrc file. If the final score is more than the specified score, it's considered a success and pylint exits with exitcode 0. Otherwise, it's considered a failure and pylint exits with its current exitcode based on the messages issued.

Close #2242
Expand Down
2 changes: 2 additions & 0 deletions doc/whatsnew/2.5.rst
Expand Up @@ -53,3 +53,5 @@ separated list of regexes, that if a name matches will be always marked as a bla
* Mutable ``collections.*`` are now flagged as dangerous defaults.

* Add new --fail-under flag for setting the threshold for the score to fail overall tests. If the score is over the fail-under threshold, pylint will complete SystemExit with value 0 to indicate no errors.

* ``ignore-patterns`` now checked against the full file path instead of the file base name
2 changes: 1 addition & 1 deletion pylint/utils/__init__.py
Expand Up @@ -44,7 +44,7 @@
from pylint.utils.ast_walker import ASTWalker
from pylint.utils.file_state import FileState
from pylint.utils.utils import (
_basename_in_blacklist_re,
_is_in_blacklist_re,
_check_csv,
_format_option_value,
_splitstrip,
Expand Down
10 changes: 5 additions & 5 deletions pylint/utils/utils.py
Expand Up @@ -91,18 +91,18 @@ def tokenize_module(module):
return list(tokenize.tokenize(readline))


def _basename_in_blacklist_re(base_name, black_list_re):
def _is_in_blacklist_re(path, black_list_re):
"""Determines if the basename is matched in a regex blacklist
:param str base_name: The basename of the file
:param str path: The file path
:param list black_list_re: A collection of regex patterns to match against.
Successful matches are blacklisted.
:returns: `True` if the basename is blacklisted, `False` otherwise.
:rtype: bool
"""
for file_pattern in black_list_re:
if file_pattern.match(base_name):
if file_pattern.match(path):
return True
return False

Expand All @@ -125,7 +125,7 @@ def expand_modules(files_or_modules, black_list, black_list_re):
for something in files_or_modules:
if basename(something) in black_list:
continue
if _basename_in_blacklist_re(basename(something), black_list_re):
if _is_in_blacklist_re(something, black_list_re):
continue
if exists(something):
# this is a file or a directory
Expand Down Expand Up @@ -185,7 +185,7 @@ def expand_modules(files_or_modules, black_list, black_list_re):
):
if filepath == subfilepath:
continue
if _basename_in_blacklist_re(basename(subfilepath), black_list_re):
if _is_in_blacklist_re(basename(subfilepath), black_list_re):
continue

modpath = _modpath_from_file(subfilepath, is_namespace)
Expand Down
12 changes: 6 additions & 6 deletions tests/utils/unittest_utils.py
Expand Up @@ -22,16 +22,16 @@
from pylint.utils import utils


def test__basename_in_blacklist_re_match():
def test__is_in_blacklist_re_match():
patterns = [re.compile(".*enchilada.*"), re.compile("unittest_.*")]
assert utils._basename_in_blacklist_re("unittest_utils.py", patterns)
assert utils._basename_in_blacklist_re("cheese_enchiladas.xml", patterns)
assert utils._is_in_blacklist_re("unittest_utils.py", patterns)
assert utils._is_in_blacklist_re("cheese_enchiladas.xml", patterns)


def test__basename_in_blacklist_re_nomatch():
def test__is_in_blacklist_re_nomatch():
patterns = [re.compile(".*enchilada.*"), re.compile("unittest_.*")]
assert not utils._basename_in_blacklist_re("test_utils.py", patterns)
assert not utils._basename_in_blacklist_re("enchilad.py", patterns)
assert not utils._is_in_blacklist_re("test_utils.py", patterns)
assert not utils._is_in_blacklist_re("enchilad.py", patterns)


def test_decoding_stream_unknown_encoding():
Expand Down

0 comments on commit d574e15

Please sign in to comment.