File size: 1,067 Bytes
e1d6e8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
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 []