Do not call `split_match` with None
`split_match` has no context available to do anything useful with `None`.
Essentially we filter these 'empty' errors at a later point.
Print debug message if we have no matches in multiline mode. Fixes
Print actual line that did not match in singleline mode.
@@ -928,15 +928,22 @@ class Linter(metaclass=LinterMeta):
in output.
"""
if self.multiline:
- errors = self.regex.finditer(output)
- if errors:
- for error in errors:
- yield self.split_match(error)
- else:
- yield self.split_match(None)
+ matches = list(self.regex.finditer(output))
+ if not matches:
+ persist.debug(
+ '{}: No matches for regex: {}'.format(self.name, self.regex.pattern))
+ return
+
+ for match in matches:
+ yield self.split_match(match)
else:
for line in output.splitlines():
- yield self.split_match(self.regex.match(line.rstrip()))
+ match = self.regex.match(line.rstrip())
+ if match:
+ yield self.split_match(match)
+ else:
+ persist.debug(
+ "{}: No match for line: '{}'".format(self.name, line))
def split_match(self, match):
"""
@@ -949,9 +956,6 @@ class Linter(metaclass=LinterMeta):
"""
match_dict = MATCH_DICT.copy()
- if not match:
- persist.debug('No match for regex: {}'.format(self.regex.pattern))
- else:
match_dict.update({
k: v
for k, v in match.groupdict().items()
