summaryrefslogtreecommitdiff
path: root/pylint/utils.py
diff options
context:
space:
mode:
authorAru Sahni <arusahni@gmail.com>2015-12-09 17:52:43 -0500
committerClaudiu Popa <pcmanticore@gmail.com>2016-01-09 22:18:48 +0200
commit2ec342e612c730a266413783918f4a0d41441ca5 (patch)
tree5efcecbb5144e04dc80bc4062f1137249203b88f /pylint/utils.py
parent97bb5a65d50dccea4d1199a5fc5a261f568c1b3f (diff)
downloadpylint-git-2ec342e612c730a266413783918f4a0d41441ca5.tar.gz
Add the ability to ignore files based on regex matching.
This addresses issue #156 by allowing for multiple ignore patterns to be specified. Rather than clobber the existing ignore option, I've introduced a new one called ignore-patterns. That way there are as few surprises as something involving regular expressions can have. Multiple patterns must be separated by a comma. For example, if I wanted to ignore all files that started with `test_` and `_`, I'd pass this in: `--ignore-patterns="test_.*","_.*"`. Close #156
Diffstat (limited to 'pylint/utils.py')
-rw-r--r--pylint/utils.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/pylint/utils.py b/pylint/utils.py
index d2bca89e5..9385401b7 100644
--- a/pylint/utils.py
+++ b/pylint/utils.py
@@ -803,8 +803,22 @@ class ReportsHandlerMixIn(object):
self.stats[key] = value
return self.stats
+def _basename_in_blacklist_re(base_name, black_list_re):
+ """Determines if the basename is matched in a regex blacklist
-def expand_modules(files_or_modules, black_list):
+ :param base_name: The basename of the file
+ :param black_list_re: A collection of regex patterns to match against. Successful matches are
+ blacklisted.
+ :returns: `True` if the basename is blacklisted, `False` otherwise.
+
+ """
+
+ for file_pattern in black_list_re:
+ if file_pattern.match(base_name):
+ return True
+ return False
+
+def expand_modules(files_or_modules, black_list, black_list_re):
"""take a list of files/modules/packages and return the list of tuple
(file, module name) which have to be actually checked
"""
@@ -841,6 +855,8 @@ def expand_modules(files_or_modules, black_list):
for subfilepath in get_module_files(dirname(filepath), black_list):
if filepath == subfilepath:
continue
+ if _basename_in_blacklist_re(basename(subfilepath), black_list_re):
+ continue
submodname = '.'.join(modpath_from_file(subfilepath))
result.append({'path': subfilepath, 'name': submodname,
'isarg': False,