Skip to content

Commit

Permalink
ruff: load all the error codes at once
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup committed Aug 27, 2024
1 parent e67d200 commit 1d5dcff
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions vcs-diff-lint-csdiff-ruff
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ def ruff_check():
return json.loads(out)


def ruff_code_to_name(code):
def ruff_code_to_name():
"""
Convert noqa code e.g. F401 to its human-readable name, e.g. unused-import
Introspect ruff and map all possible noqa codes to a human-readable names.
"""
# This implementation will likely kill all ruff performance benefits
cmd = ["ruff", "rule", code, "--output-format=json"]
cmd = ["ruff", "rule", "--all", "--output-format=json"]
with Popen(cmd, stdout=PIPE) as proc:
out, _err = proc.communicate(timeout=60)
data = json.loads(out)
return data["name"]
return {i["code"]: i["name"] for i in json.loads(out)}


def main():
"""
The main fuction
"""
defects = ruff_check()
code_to_name_map = ruff_code_to_name()

for defect in defects:
path = os.path.relpath(defect["filename"])
column = defect["location"]["column"] or ""
colsep = ":" if column else ""
event = "{0}[{1}]".format(
defect["code"], ruff_code_to_name(defect["code"]))
defect["code"], code_to_name_map[defect["code"]])

print("Error: RUFF_WARNING:")
print("{file}:{line}{colsep}{column}: {event}: {msg}".format(
Expand Down

0 comments on commit 1d5dcff

Please sign in to comment.