Skip to content

Commit

Permalink
Fix division by zero error in ecosystem check (#11469)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb authored May 19, 2024
1 parent d9ec3d5 commit 46fcd19
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion python/ruff-ecosystem/ruff_ecosystem/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,20 @@ def markdown_check_result(result: Result) -> str:

# Limit the number of items displayed per project to between 10 and 50
# based on the proportion of total changes present in this project
max_display_per_project = max(10, int((project_changes / total_changes) * 50))
max_display_per_project = max(
10,
int(
(
# TODO(zanieb): We take the `max` here to avoid division by zero errors where
# `total_changes` is zero but `total_affected_rules` is non-zero so we did not
# 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.
project_changes / max(total_changes, 1)
)
* 50
),
)

# 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)
Expand Down

0 comments on commit 46fcd19

Please sign in to comment.