From 96549321431557ca93f97a96f7b5ed252c74d4d1 Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Thu, 12 Jun 2025 06:14:11 -0400 Subject: [PATCH] Flatten the logic for quality report violations --- diff_cover/violationsreporters/base.py | 36 +++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/diff_cover/violationsreporters/base.py b/diff_cover/violationsreporters/base.py index 3f1a6ca0..26245c09 100644 --- a/diff_cover/violationsreporters/base.py +++ b/diff_cover/violationsreporters/base.py @@ -150,27 +150,27 @@ def violations(self, src_path): """ if not any(src_path.endswith(ext) for ext in self.driver.supported_extensions): return [] + if src_path not in self.violations_dict: if self.reports: self.violations_dict = self.driver.parse_reports(self.reports) - else: - if self.driver_tool_installed is None: - self.driver_tool_installed = self.driver.installed() - if not self.driver_tool_installed: - raise OSError(f"{self.driver.name} is not installed") - command = copy.deepcopy(self.driver.command) - if self.options: - for arg in self.options.split(): - command.append(arg) - if os.path.exists(src_path): - command.append(src_path.encode(sys.getfilesystemencoding())) - - output = execute(command, self.driver.exit_codes) - if self.driver.output_stderr: - output = output[1] - else: - output = output[0] - self.violations_dict.update(self.driver.parse_reports([output])) + return self.violations_dict[src_path] + + if self.driver_tool_installed is None: + self.driver_tool_installed = self.driver.installed() + if not self.driver_tool_installed: + msg = f"{self.driver.name} is not installed" + raise OSError(msg) + command = copy.deepcopy(self.driver.command) + if self.options: + for arg in self.options.split(): + command.append(arg) + if os.path.exists(src_path): + command.append(src_path.encode(sys.getfilesystemencoding())) + + stdout, stderr = execute(command, self.driver.exit_codes) + output = stderr if self.driver.output_stderr else stdout + self.violations_dict.update(self.driver.parse_reports([output])) return self.violations_dict[src_path]