Add analyzers module (base, factory, Python, JavaScript)
This commit is contained in:
35
vibeguard/analyzers/base.py
Normal file
35
vibeguard/analyzers/base.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
"""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)
|
||||||
Reference in New Issue
Block a user