Allow post filters via setting `filter_errors`
`filter_errors` takes a list of regexes which will get matched against
the string "{code}: {message}".
@@ -920,7 +920,26 @@ class Linter(metaclass=LinterMeta):
raise TransientError('View not consistent.')
virtual_view = VirtualView(code)
- return self.parse_output(output, virtual_view)
+ return self.filter_errors(self.parse_output(output, virtual_view))
+
+ def filter_errors(self, errors):
+ try:
+ filters = [
+ re.compile(pattern, re.I)
+ for pattern in self.get_view_settings().get('filter_errors', [])
+ ]
+ except re.error as err:
+ logger.warning("RegEx error in 'filter_errors': '{}'".format(err))
+ filters = []
+
+ return [
+ error
+ for error in errors
+ if not any(
+ pattern.search(': '.join([error['code'], error['msg']]))
+ for pattern in filters
+ )
+ ]
def parse_output(self, proc, virtual_view):
# Note: We support type str for `proc`. E.g. the user might have
@@ -946,14 +965,13 @@ class Linter(metaclass=LinterMeta):
def parse_output_via_regex(self, output, virtual_view):
if not output:
logger.info('{}: no output'.format(self.name))
- return []
+ return
if logger.isEnabledFor(logging.INFO):
import textwrap
logger.info('{}: output:\n{}'.format(
self.name, textwrap.indent(output.strip(), ' ')))
- errors = []
for m in self.find_errors(output):
if not m or not m[0]:
continue
@@ -962,10 +980,7 @@ class Linter(metaclass=LinterMeta):
m = LintMatch(*m)
if m.message and m.line is not None:
- error = self.process_match(m, virtual_view)
- errors.append(error)
-
- return errors
+ yield self.process_match(m, virtual_view)
def find_errors(self, output):
"""
