BuddAI/validators/base_validator.py
JamesTheGiblet d4e09f6d13 Add unit tests for analytics, fallback client, and refactored validators
- Implemented comprehensive unit tests for the BuddAI Analytics module, covering fallback statistics calculations.
- Created tests for the FallbackClient to ensure proper escalation to various AI models and handling of missing API keys.
- Developed unit tests for the refactored validator system, validating various hardware and coding standards.
- Established a base validator interface and implemented specific validators for ESP32, Arduino, motor control, memory safety, and more.
- Enhanced the validator registry to auto-discover and manage validators effectively.
- Included detailed validation logic for common issues in embedded systems programming, such as unused variables, safety timeouts, and coding style violations.
2026-01-08 17:43:11 +00:00

40 lines
No EOL
1.1 KiB
Python

"""
Base validator interface
All validators inherit from this
"""
class BaseValidator:
"""Base class for all validators"""
name = "Base Validator"
triggers = [] # Keywords that activate this validator
priority = 5 # 1=critical, 10=nice-to-have
def validate(self, code: str, context: dict) -> list:
"""
Validate code and return issues
Args:
code: The code to validate
context: Dict with hardware, libraries, etc.
Returns:
List of issue dicts:
{
'severity': 'error|warning|info',
'line': line_number or None,
'message': 'What is wrong',
'fix': 'How to fix it'
}
"""
raise NotImplementedError
def matches_context(self, code: str, context: dict) -> bool:
"""
Check if this validator should run
Returns:
bool: True if any trigger keyword in code
"""
code_lower = code.lower()
return any(trigger.lower() in code_lower for trigger in self.triggers)