summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lint.py18
-rw-r--r--test/unittest_lint.py7
2 files changed, 25 insertions, 0 deletions
diff --git a/lint.py b/lint.py
index 30f83de..7f736f5 100644
--- a/lint.py
+++ b/lint.py
@@ -563,6 +563,22 @@ This is used by the global evaluation report (RP0004).'}),
checker.active_msgs = messages
return neededcheckers
+ def should_analyze_file(self, modname, path):
+ """Returns whether or not a module should be checked.
+
+ This implementation returns True for all inputs, indicating that all
+ files should be linted.
+
+ Subclasses may override this method to indicate that modules satisfying
+ certain conditions should not be linted.
+
+ :param str modname: The name of the module to be checked.
+ :param str path: The full path to the source code of the module.
+ :returns: True if the module should be checked.
+ :rtype: bool
+ """
+ return True
+
def check(self, files_or_modules):
"""main checking entry: check a list of files or modules from their
name.
@@ -582,6 +598,8 @@ This is used by the global evaluation report (RP0004).'}),
# build ast and check modules or packages
for descr in self.expand_files(files_or_modules):
modname, filepath = descr['name'], descr['path']
+ if not self.should_analyze_file(modname, filepath):
+ continue
if self.config.files_output:
reportfile = 'pylint_%s.%s' % (modname, self.reporter.extension)
self.reporter.set_output(open(reportfile, 'w'))
diff --git a/test/unittest_lint.py b/test/unittest_lint.py
index f6ed6a2..579ffc1 100644
--- a/test/unittest_lint.py
+++ b/test/unittest_lint.py
@@ -282,6 +282,13 @@ class PyLinterTC(TestCase):
except:
pass
+ def test_lint_should_analyze_file(self):
+ self.linter.set_reporter(text.TextReporter())
+ self.linter.config.files_output = True
+ self.linter.should_analyze_file = lambda *args: False
+ self.linter.check('os')
+ self.assertFalse(os.path.exists('pylint_os.txt'))
+
def test_enable_report(self):
self.assertEqual(self.linter.report_is_enabled('RP0001'), True)
self.linter.disable('RP0001')