From 0a24d70bfd7210ae8c796db2efb6d76ab6699f91 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 25 Jun 2024 13:48:25 +0100 Subject: [PATCH] [Ruff v0.5] Fix `ZeroDivisionError`s in the ecosystem check (#12027) Seen in CI in https://github.com/astral-sh/ruff/pull/12026 --- python/ruff-ecosystem/ruff_ecosystem/check.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python/ruff-ecosystem/ruff_ecosystem/check.py b/python/ruff-ecosystem/ruff_ecosystem/check.py index 76f0710299..7aa6cdda13 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/check.py +++ b/python/ruff-ecosystem/ruff_ecosystem/check.py @@ -153,6 +153,9 @@ def markdown_check_result(result: Result) -> str: # skip display. This shouldn't really happen and indicates a problem in the # calculation of these values. Instead of skipping entirely when `total_changes` # is zero, we'll attempt to report the results to help diagnose the problem. + # + # There's similar issues with the `max_display_per_rule` calculation immediately + # below as well. project_changes / max(total_changes, 1) ) * 50 @@ -162,7 +165,11 @@ def markdown_check_result(result: Result) -> str: # Limit the number of items displayed per rule to between 5 and the max for # the project based on the number of rules affected (less rules, more per rule) max_display_per_rule = max( - 5, max_display_per_project // len(rule_changes.rule_codes()) + 5, + # TODO: remove the need for the max() call here, + # which is a workaround for if `len(rule_changes.rule_codes()) == 0` + # (see comment in the assignment of `max_display_per_project` immediately above) + max_display_per_project // max(len(rule_changes.rule_codes()), 1), ) # Display the diff