tools/quality_scan.py +4−1 View file@@ -9,6 +9,9 @@ from pathlib import Path
9 9
10 10
ROOT = Path(__file__).resolve().parents[1]11 11
SCHEMA = "asw.quality-result/v1" 12 +
BRANCH_NODES = (ast.If, ast.For, ast.AsyncFor, ast.While, ast.Try, ast.BoolOp) 13 +
if hasattr(ast, "Match"): 14 +
BRANCH_NODES += (ast.Match,)12 15
13 16
14 17
def write_result(path: str, payload: dict) -> None:@@ -38,7 +41,7 @@ def static_analysis() -> dict:
38 41
for node in ast.walk(tree):39 42
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):40 43
functions += 141 −
complexity = 1 + sum(isinstance(item, (ast.If, ast.For, ast.AsyncFor, ast.While, ast.Try, ast.BoolOp, ast.Match)) for item in ast.walk(node)) 44 +
complexity = 1 + sum(isinstance(item, BRANCH_NODES) for item in ast.walk(node))42 45
maximum_complexity = max(maximum_complexity, complexity)43 46
if complexity > 12:44 47
issues.append({"rule": "PY-COMPLEXITY", "severity": "MEDIUM", "path": relative, "line": node.lineno, "message": f"{node.name} complexity {complexity} exceeds warning threshold 12"})