refactor: modernize code quality tooling with Ruff
- Replace black, isort, and flake8 with Ruff (all-in-one linter and formatter) - Add comprehensive pyproject.toml configuration - Simplify Makefile code quality targets - Configure exclusions for venv/.venv in pyproject.toml - Auto-fix 1,359 linting issues across codebase Benefits: - Much faster builds (Ruff is written in Rust) - Single tool replaces multiple tools - More comprehensive rule set (UP, B, C4, SIM, PIE, RET, Q) - All configuration centralized in pyproject.toml - Better import sorting and formatting consistency 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -25,7 +25,7 @@ import sys
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Tuple
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
|
||||
@@ -56,7 +56,7 @@ class Violation:
|
||||
class ValidationResult:
|
||||
"""Results of architecture validation"""
|
||||
|
||||
violations: List[Violation] = field(default_factory=list)
|
||||
violations: list[Violation] = field(default_factory=list)
|
||||
files_checked: int = 0
|
||||
rules_applied: int = 0
|
||||
|
||||
@@ -80,13 +80,13 @@ class ArchitectureValidator:
|
||||
self.result = ValidationResult()
|
||||
self.project_root = Path.cwd()
|
||||
|
||||
def _load_config(self) -> Dict[str, Any]:
|
||||
def _load_config(self) -> dict[str, Any]:
|
||||
"""Load validation rules from YAML config"""
|
||||
if not self.config_path.exists():
|
||||
print(f"❌ Configuration file not found: {self.config_path}")
|
||||
sys.exit(1)
|
||||
|
||||
with open(self.config_path, "r") as f:
|
||||
with open(self.config_path) as f:
|
||||
config = yaml.safe_load(f)
|
||||
|
||||
print(f"📋 Loaded architecture rules: {config.get('project', 'unknown')}")
|
||||
@@ -144,7 +144,7 @@ class ArchitectureValidator:
|
||||
# API-004: Check authentication
|
||||
self._check_endpoint_authentication(file_path, content, lines)
|
||||
|
||||
def _check_pydantic_usage(self, file_path: Path, content: str, lines: List[str]):
|
||||
def _check_pydantic_usage(self, file_path: Path, content: str, lines: list[str]):
|
||||
"""API-001: Ensure endpoints use Pydantic models"""
|
||||
rule = self._get_rule("API-001")
|
||||
if not rule:
|
||||
@@ -180,7 +180,7 @@ class ArchitectureValidator:
|
||||
)
|
||||
|
||||
def _check_no_business_logic_in_endpoints(
|
||||
self, file_path: Path, content: str, lines: List[str]
|
||||
self, file_path: Path, content: str, lines: list[str]
|
||||
):
|
||||
"""API-002: Ensure no business logic in endpoints"""
|
||||
rule = self._get_rule("API-002")
|
||||
@@ -213,7 +213,7 @@ class ArchitectureValidator:
|
||||
)
|
||||
|
||||
def _check_endpoint_exception_handling(
|
||||
self, file_path: Path, content: str, lines: List[str]
|
||||
self, file_path: Path, content: str, lines: list[str]
|
||||
):
|
||||
"""API-003: Check proper exception handling in endpoints"""
|
||||
rule = self._get_rule("API-003")
|
||||
@@ -263,7 +263,7 @@ class ArchitectureValidator:
|
||||
)
|
||||
|
||||
def _check_endpoint_authentication(
|
||||
self, file_path: Path, content: str, lines: List[str]
|
||||
self, file_path: Path, content: str, lines: list[str]
|
||||
):
|
||||
"""API-004: Check authentication on endpoints"""
|
||||
rule = self._get_rule("API-004")
|
||||
@@ -321,7 +321,7 @@ class ArchitectureValidator:
|
||||
self._check_db_session_parameter(file_path, content, lines)
|
||||
|
||||
def _check_no_http_exception_in_services(
|
||||
self, file_path: Path, content: str, lines: List[str]
|
||||
self, file_path: Path, content: str, lines: list[str]
|
||||
):
|
||||
"""SVC-001: Services must not raise HTTPException"""
|
||||
rule = self._get_rule("SVC-001")
|
||||
@@ -357,7 +357,7 @@ class ArchitectureValidator:
|
||||
)
|
||||
|
||||
def _check_service_exceptions(
|
||||
self, file_path: Path, content: str, lines: List[str]
|
||||
self, file_path: Path, content: str, lines: list[str]
|
||||
):
|
||||
"""SVC-002: Check for proper exception handling"""
|
||||
rule = self._get_rule("SVC-002")
|
||||
@@ -379,7 +379,7 @@ class ArchitectureValidator:
|
||||
)
|
||||
|
||||
def _check_db_session_parameter(
|
||||
self, file_path: Path, content: str, lines: List[str]
|
||||
self, file_path: Path, content: str, lines: list[str]
|
||||
):
|
||||
"""SVC-003: Service methods should accept db session as parameter"""
|
||||
rule = self._get_rule("SVC-003")
|
||||
@@ -536,7 +536,7 @@ class ArchitectureValidator:
|
||||
suggestion="Add {% extends 'admin/base.html' %} at the top",
|
||||
)
|
||||
|
||||
def _get_rule(self, rule_id: str) -> Dict[str, Any]:
|
||||
def _get_rule(self, rule_id: str) -> dict[str, Any]:
|
||||
"""Get rule configuration by ID"""
|
||||
# Look in different rule categories
|
||||
for category in [
|
||||
@@ -618,14 +618,13 @@ class ArchitectureValidator:
|
||||
print("❌ VALIDATION FAILED - Fix errors before committing")
|
||||
print("=" * 80)
|
||||
return 1
|
||||
elif self.result.has_warnings():
|
||||
if self.result.has_warnings():
|
||||
print("⚠️ VALIDATION PASSED WITH WARNINGS")
|
||||
print("=" * 80)
|
||||
return 0
|
||||
else:
|
||||
print("✅ VALIDATION PASSED - No violations found")
|
||||
print("=" * 80)
|
||||
return 0
|
||||
print("✅ VALIDATION PASSED - No violations found")
|
||||
print("=" * 80)
|
||||
return 0
|
||||
|
||||
def print_json(self) -> int:
|
||||
"""Print validation results as JSON"""
|
||||
|
||||
Reference in New Issue
Block a user