Files
noteflow/check_violations.py
2026-01-22 15:34:56 +00:00

62 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Quick script to check long parameter list violations."""
from __future__ import annotations
import importlib
import sys
from collections.abc import Mapping
from typing import Protocol, cast
sys.path.insert(0, "/home/trav/repos/noteflow/tests")
sys.path.insert(0, "/home/trav/repos/noteflow/src")
class Violation(Protocol):
stable_id: str
relative_path: str
identifier: str
detail: str
class CollectLongParameterLists(Protocol):
def __call__(self, *, parse_errors: list[str]) -> list[Violation]: ...
def load_collectors() -> tuple[CollectLongParameterLists, Mapping[str, set[str]]]:
code_smells = importlib.import_module("quality._detectors.code_smells")
baseline_module = importlib.import_module("quality._baseline")
collect = cast(CollectLongParameterLists, getattr(code_smells, "collect_long_parameter_lists"))
baseline = cast(Mapping[str, set[str]], getattr(baseline_module, "load_baseline")())
return collect, baseline
collect_long_parameter_lists, baseline = load_collectors()
parse_errors: list[str] = []
violations = collect_long_parameter_lists(parse_errors=parse_errors)
allowed_ids = baseline.get("long_parameter_list", set())
current_ids = {v.stable_id for v in violations}
new_ids = current_ids - allowed_ids
new_violations = [v for v in violations if v.stable_id in new_ids]
print(f"Total violations found: {len(violations)}")
print(f"Baseline allows: {len(allowed_ids)}")
print(f"NEW violations (not in baseline): {len(new_violations)}")
print()
if new_violations:
print("NEW VIOLATIONS:")
for v in sorted(new_violations, key=lambda x: x.stable_id):
print(f" {v.relative_path}:{v.identifier} ({v.detail})")
else:
print("No new violations - test would PASS")
if parse_errors:
print(f"\nParse errors: {len(parse_errors)}")
for e in parse_errors[:5]:
print(f" {e}")