From 9f5102d536d8366c4c18814720ecd62a7e9a62c1 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Fri, 27 Oct 2023 22:04:52 -0500 Subject: [PATCH] Improve calculation of max display per rule in ecosystem checks (#8291) Fixes bug where `total_affected_rules` is empty, a division by zero error can occur if there are only errors and no rule changes. Calculates the maximum display per rule with the calculated project maximum as the upper bound instead of 50, this should show more rule variety when project maximums are lower. This commit was meant to be in #8223 but I missed it. --- python/ruff-ecosystem/ruff_ecosystem/check.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/python/ruff-ecosystem/ruff_ecosystem/check.py b/python/ruff-ecosystem/ruff_ecosystem/check.py index becf357cee..3e2462ffeb 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/check.py +++ b/python/ruff-ecosystem/ruff_ecosystem/check.py @@ -99,14 +99,6 @@ def markdown_check_result(result: Result) -> str: ) lines.append("") - # Limit the number of items displayed per rule to between 5 and 50 - max_display_per_rule = max( - 5, - # Calculate the number of affected rules that we would display to increase - # the maximum if there are less rules affected - 50 // total_affected_rules, - ) - # Display per project changes for project, comparison in result.completed: # TODO: This is not a performant way to check the length but the whole @@ -136,9 +128,15 @@ def markdown_check_result(result: Result) -> str: ) # Limit the number of items displayed per project to between 10 and 50 - # based on the number of total changes present in this project + # based on the proportion of total changes present in this project max_display_per_project = max(10, int((project_changes / total_changes) * 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) + max_display_per_rule = max( + 5, max_display_per_project // len(rule_changes.rule_codes()) + ) + # Display the diff displayed_changes_per_rule = Counter() displayed_changes = 0