mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-02 18:02:23 +00:00
List rule changes in ecosystem (#4371)
* Count changes for each rule * Handle case where rule matches were found in a line * List and sort by changes * Remove detail from rule changes * Add comment about leading : * Only print rule changes if rule changes are present * Use re.search and match group * Remove dict().items() * Use match group to extract rule code
This commit is contained in:
parent
bbadbb5de5
commit
b76b4b6016
1 changed files with 39 additions and 0 deletions
|
@ -255,6 +255,7 @@ async def main(*, ruff1: Path, ruff2: Path, projects_jsonl: Optional[Path]) -> N
|
|||
if total_removed == 0 and total_added == 0 and errors == 0:
|
||||
print("\u2705 ecosystem check detected no changes.")
|
||||
else:
|
||||
rule_changes: dict[str, tuple[int, int]] = {}
|
||||
changes = f"(+{total_added}, -{total_removed}, {errors} error(s))"
|
||||
|
||||
print(f"\u2139\ufe0f ecosystem check **detected changes**. {changes}")
|
||||
|
@ -294,9 +295,47 @@ async def main(*, ruff1: Path, ruff2: Path, projects_jsonl: Optional[Path]) -> N
|
|||
print()
|
||||
print("</p>")
|
||||
print("</details>")
|
||||
|
||||
# Count rule changes
|
||||
for line in diff_str.splitlines():
|
||||
# Find rule change for current line or construction
|
||||
# + <rule>/<path>:<line>:<column>: <rule_code> <message>
|
||||
matches = re.search(r": ([A-Z]{1,3}[0-9]{3,4})", line)
|
||||
|
||||
if matches is None:
|
||||
# Handle case where there are no regex matches e.g.
|
||||
# + "?application=AIRFLOW&authenticator=TEST_AUTH&role=TEST_ROLE&warehouse=TEST_WAREHOUSE" # noqa: E501, ERA001
|
||||
# Which was found in local testing
|
||||
continue
|
||||
|
||||
rule_code = matches.group(1)
|
||||
|
||||
# Get current additions and removals for this rule
|
||||
current_changes = rule_changes.get(rule_code, (0, 0))
|
||||
|
||||
# Check if addition or removal depending on the first character
|
||||
if line[0] == "+":
|
||||
current_changes = (current_changes[0] + 1, current_changes[1])
|
||||
elif line[0] == "-":
|
||||
current_changes = (current_changes[0], current_changes[1] + 1)
|
||||
|
||||
rule_changes[rule_code] = current_changes
|
||||
|
||||
else:
|
||||
continue
|
||||
|
||||
if len(rule_changes.keys()) > 0:
|
||||
print(f"Rules changed: {len(rule_changes.keys())}")
|
||||
print()
|
||||
print("| Rule | Changes | Additions | Removals |")
|
||||
print("| ---- | ------- | --------- | -------- |")
|
||||
for rule, (additions, removals) in sorted(
|
||||
rule_changes.items(),
|
||||
key=lambda x: (x[1][0] + x[1][1]),
|
||||
reverse=True,
|
||||
):
|
||||
print(f"| {rule} | {additions + removals} | {additions} | {removals} |")
|
||||
|
||||
logger.debug(f"Finished {len(repositories)} repositories")
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue