"""Adapter: ruff check --output-format=json normalized to Finding[].""" from __future__ import annotations import json from scripts.manifest import Finding def _severity_for_rule(code: str) -> str: if not code: return "low" if code.startswith("S"): return "high" if code.startswith("B"): return "medium" return "low" def parse_ruff_output(stdout: str) -> list[Finding]: try: payload = json.loads(stdout) except json.JSONDecodeError: return [] if not isinstance(payload, list): return [] out: list[Finding] = [] for item in payload: loc = item.get("location") or {} end = item.get("end_location") or loc code = item.get("code", "") out.append(Finding( tool="ruff", rule_id=code, severity=_severity_for_rule(code), file=item.get("filename", ""), line=loc.get("row", 0), end_line=end.get("row", loc.get("row", 0)), message=item.get("message", ""), )) return out