Files
vibeguard/vibeguard/analyzers/base.py
7000pctAUTO 1e3c5f00f1
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
Add analyzers module (base, factory, Python, JavaScript)
2026-02-03 06:57:50 +00:00

36 lines
1.1 KiB
Python

"""Base analyzer class for VibeGuard."""
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Any
class BaseAnalyzer(ABC):
"""Base class for all language analyzers."""
LANGUAGE_NAME: str = "base"
FILE_EXTENSIONS: list[str] = []
@abstractmethod
def parse_file(self, path: Path) -> Any | None:
"""Parse a file and return the AST/tree."""
pass
@abstractmethod
def analyze(self, tree: Any, path: Path) -> list[dict[str, Any]]:
"""Analyze a parsed tree for anti-patterns."""
pass
def get_language(self) -> str:
"""Get the language name for this analyzer."""
return self.LANGUAGE_NAME
def supports_extension(self, ext: str) -> bool:
"""Check if this analyzer supports a file extension."""
return ext in self.FILE_EXTENSIONS
def get_severity_score(self, severity: str) -> int:
"""Convert severity string to numeric score for sorting."""
scores = {"critical": 4, "error": 3, "warning": 2, "info": 1}
return scores.get(severity, 0)