Created
March 14, 2025 20:26
-
-
Save henryiii/2b7eca35d9d70f1ca1a0790f2830a733 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import annotations | |
import json | |
import re | |
import subprocess | |
from collections import Counter | |
from pathlib import Path | |
import tomllib | |
REGEX = re.compile(r'\d+$') | |
def find_rules() -> list[dict[str, str]]: | |
result = subprocess.run(["ruff", "rule", "--all", "--output-format=json"], stdout=subprocess.PIPE, check=True) | |
return json.loads(result.stdout) | |
def rule_sets(inp: list[dict[str, str]]) -> dict[str, tuple[str, int, int]]: | |
counts_preview = Counter(REGEX.sub("", rule["code"]) for rule in inp if rule["preview"]) | |
counts_classic = Counter(REGEX.sub("", rule["code"]) for rule in inp if not rule["preview"]) | |
return {(r := REGEX.sub("", rule["code"])): (rule["linter"], counts_preview.get(r, 0), counts_classic.get(r, 0)) for rule in inp} | |
def check_selected() -> set[str]: | |
with Path("pyproject.toml").open("rb") as f: | |
pyproject = tomllib.load(f) | |
return set(pyproject["tool"]["ruff"]["lint"]["extend-select"]) | |
selected = check_selected() | |
rules = find_rules() | |
sets = rule_sets(rules) | |
for k, v in sorted(sets.items()): | |
x = "X" if k in selected else " " | |
y = f"({v[1]:2})" if v[1] else " " | |
print(f"{v[2]:3} {y} [{x}] {k:5} {v[0]}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment