diff --git a/vibeguard/analyzers/base.py b/vibeguard/analyzers/base.py new file mode 100644 index 0000000..b15794c --- /dev/null +++ b/vibeguard/analyzers/base.py @@ -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)