-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# ruff: noqa: T201 | ||
|
||
"""Usage: ruff check --select=ALL --statistics | ./ruff_exclude.py .""" | ||
|
||
from __future__ import annotations | ||
|
||
from string import digits | ||
from subprocess import run | ||
from sys import stdin | ||
|
||
|
||
def quoted(s: str) -> str: | ||
"""Return a double-quoted string. | ||
>>> quoted("s") | ||
'"s"' | ||
>>> quoted('s') | ||
'"s"' | ||
>>> quoted(None) | ||
'"None"' | ||
""" | ||
return f'"{s}"' | ||
|
||
|
||
def ruff_linters() -> dict[str, str]: | ||
"""Call `ruff linter` and return a dict of {rule_family: description}.""" | ||
lines = run( # noqa: S603 | ||
["ruff", "linter"], # noqa: S607 | ||
capture_output=True, | ||
check=True, | ||
text=True, | ||
).stdout.splitlines() | ||
linters = { | ||
key: value for line in lines for key, value in [line.strip().split(" ", 1)] | ||
} | ||
e_w = linters.pop("E/W") | ||
linters["E"] = f"{e_w} errors" | ||
linters["W"] = f"{e_w} warnings" | ||
pylint = linters.pop("PL") | ||
linters["PLC"] = f"{pylint} conventions" | ||
linters["PLE"] = f"{pylint} errors" | ||
linters["PLR"] = f"{pylint} refactorings" | ||
linters["PLW"] = f"{pylint} warnings" | ||
return linters | ||
|
||
|
||
if __name__ == "__main__": | ||
violations = {line.split()[1].rstrip(digits) for line in stdin} | ||
lines = [ | ||
f' {"#" if key in violations else " "} {quoted(key):<7} # {value}' | ||
for key, value in ruff_linters().items() | ||
] | ||
print("[tools.ruff.lint]\nexclude = [") | ||
print("\n".join(sorted(lines))) | ||
print("]") |