Add patterns module (definitions and manager)
This commit is contained in:
64
vibeguard/patterns/definitions.py
Normal file
64
vibeguard/patterns/definitions.py
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
"""Pattern definitions for VibeGuard."""
|
||||||
|
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from enum import Enum
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
class Severity(Enum):
|
||||||
|
"""Severity levels for detected issues."""
|
||||||
|
|
||||||
|
CRITICAL = "critical"
|
||||||
|
ERROR = "error"
|
||||||
|
WARNING = "warning"
|
||||||
|
INFO = "info"
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Pattern:
|
||||||
|
"""Definition of an anti-pattern."""
|
||||||
|
|
||||||
|
id: str
|
||||||
|
name: str
|
||||||
|
description: str
|
||||||
|
severity: Severity
|
||||||
|
languages: list[str]
|
||||||
|
message: str
|
||||||
|
suggestion: str
|
||||||
|
query: str = ""
|
||||||
|
before_example: str = ""
|
||||||
|
after_example: str = ""
|
||||||
|
category: str = "general"
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Issue:
|
||||||
|
"""A detected issue in the code."""
|
||||||
|
|
||||||
|
pattern_id: str
|
||||||
|
file: str
|
||||||
|
line: int
|
||||||
|
severity: Severity
|
||||||
|
message: str
|
||||||
|
suggestion: str
|
||||||
|
language: str = ""
|
||||||
|
column: int = 0
|
||||||
|
end_line: int = 0
|
||||||
|
end_column: int = 0
|
||||||
|
code_snippet: str = ""
|
||||||
|
|
||||||
|
def to_dict(self) -> dict[str, Any]:
|
||||||
|
"""Convert issue to dictionary."""
|
||||||
|
return {
|
||||||
|
"pattern": self.pattern_id,
|
||||||
|
"file": self.file,
|
||||||
|
"line": self.line,
|
||||||
|
"severity": self.severity.value,
|
||||||
|
"message": self.message,
|
||||||
|
"suggestion": self.suggestion,
|
||||||
|
"language": self.language,
|
||||||
|
"column": self.column,
|
||||||
|
"end_line": self.end_line,
|
||||||
|
"end_column": self.end_column,
|
||||||
|
"code_snippet": self.code_snippet,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user