From b1e38646b4d6147bc24ac93d9d698adfc560b6d6 Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Thu, 12 Jun 2025 12:38:21 +0200 Subject: [PATCH] Flatten code PylintDriver.parse_reports --- .../violations_reporter.py | 58 +++++++++---------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/diff_cover/violationsreporters/violations_reporter.py b/diff_cover/violationsreporters/violations_reporter.py index 446fa179..57561cdb 100644 --- a/diff_cover/violationsreporters/violations_reporter.py +++ b/diff_cover/violationsreporters/violations_reporter.py @@ -639,7 +639,7 @@ def _process_dupe_code_violation(self, lines, current_line, message): current_line += 1 match = self.multi_line_violation_regex.match(lines[current_line]) src_path, l_number = match.groups() - src_paths.append(("%s.py" % src_path, l_number)) + src_paths.append((f"{src_path}.py", l_number)) return src_paths def parse_reports(self, reports): @@ -659,36 +659,32 @@ def parse_reports(self, reports): # Ignore any line that isn't matched # (for example, snippets from the source code) - if match is not None: - ( - pylint_src_path, - line_number, - pylint_code, - function_name, - message, - ) = match.groups() - if pylint_code == self.dupe_code_violation: - files_involved = self._process_dupe_code_violation( - output_lines, output_line_number, message - ) - else: - files_involved = [(pylint_src_path, line_number)] - - for violation in files_involved: - pylint_src_path, line_number = violation - # pylint might uses windows paths - pylint_src_path = util.to_unix_path(pylint_src_path) - # If we're looking for a particular source file, - # ignore any other source files. - if function_name: - error_str = "{}: {}: {}".format( - pylint_code, function_name, message - ) - else: - error_str = f"{pylint_code}: {message}" - - violation = Violation(int(line_number), error_str) - violations_dict[pylint_src_path].append(violation) + if match is None: + continue + + ( + pylint_src_path, + line_number, + pylint_code, + function_name, + message, + ) = match.groups() + files_involved = [(pylint_src_path, line_number)] + if pylint_code == self.dupe_code_violation: + files_involved = self._process_dupe_code_violation( + output_lines, output_line_number, message + ) + + for pylint_src_path, line_number in files_involved: + # If we're looking for a particular source file, + # ignore any other source files. + error_str = f"{pylint_code}: {message}" + if function_name: + error_str = f"{pylint_code}: {function_name}: {message}" + + clean_path = util.to_unix_path(pylint_src_path) + violation = Violation(int(line_number), error_str) + violations_dict[clean_path].append(violation) return violations_dict