3v324v23's picture
code agent
e1d6e8a
"""
Very simple static analyzer (Python only for v0.1)
"""
import subprocess
import shutil
from typing import List, Dict
def run_python_flake(path: str) -> List[Dict]:
if shutil.which("flake8") is None:
return []
try:
out = subprocess.check_output(["flake8", path, "--format=%(row)d:%(col)d:%(code)s:%(text)s"], stderr=subprocess.STDOUT)
text = out.decode("utf-8", errors="ignore").strip()
findings = []
for line in text.splitlines():
parts = line.split(":", 3)
if len(parts) == 4:
row, col, code, msg = parts
findings.append({
"tool": "flake8",
"code": code,
"line": int(row),
"col": int(col),
"message": msg.strip()
})
return findings
except subprocess.CalledProcessError:
return []
def quick_analyze(path: str, language: str) -> List[Dict]:
if language == "python":
return run_python_flake(path)
return []