Add ruff linter/formatter for Python
- Add ruff as dev dependency - Configure ruff in pyproject.toml with strict 88-char line limit - Ignore B008 (FastAPI Depends pattern is standard) - Allow longer lines in tests for readability - Fix all lint issues in source files - Add Makefile targets: lint-backend, format-backend, fix-backend
This commit is contained in:
parent
69bc8413e0
commit
6c218130e9
31 changed files with 1234 additions and 876 deletions
|
|
@ -1,8 +1,9 @@
|
|||
"""Validate shared constants match backend definitions."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from models import ROLE_ADMIN, ROLE_REGULAR, InviteStatus, AppointmentStatus
|
||||
from models import ROLE_ADMIN, ROLE_REGULAR, AppointmentStatus, InviteStatus
|
||||
|
||||
|
||||
def validate_shared_constants() -> None:
|
||||
|
|
@ -11,13 +12,13 @@ def validate_shared_constants() -> None:
|
|||
Raises ValueError if there's a mismatch.
|
||||
"""
|
||||
constants_path = Path(__file__).parent.parent / "shared" / "constants.json"
|
||||
|
||||
|
||||
if not constants_path.exists():
|
||||
raise ValueError(f"Shared constants file not found: {constants_path}")
|
||||
|
||||
|
||||
with open(constants_path) as f:
|
||||
constants = json.load(f)
|
||||
|
||||
|
||||
# Validate roles
|
||||
expected_roles = {"ADMIN": ROLE_ADMIN, "REGULAR": ROLE_REGULAR}
|
||||
if constants.get("roles") != expected_roles:
|
||||
|
|
@ -25,39 +26,46 @@ def validate_shared_constants() -> None:
|
|||
f"Role mismatch in shared/constants.json. "
|
||||
f"Expected: {expected_roles}, Got: {constants.get('roles')}"
|
||||
)
|
||||
|
||||
|
||||
# Validate invite statuses
|
||||
expected_invite_statuses = {s.name: s.value for s in InviteStatus}
|
||||
if constants.get("inviteStatuses") != expected_invite_statuses:
|
||||
got = constants.get("inviteStatuses")
|
||||
raise ValueError(
|
||||
f"Invite status mismatch in shared/constants.json. "
|
||||
f"Expected: {expected_invite_statuses}, Got: {constants.get('inviteStatuses')}"
|
||||
f"Invite status mismatch. Expected: {expected_invite_statuses}, Got: {got}"
|
||||
)
|
||||
|
||||
|
||||
# Validate appointment statuses
|
||||
expected_appointment_statuses = {s.name: s.value for s in AppointmentStatus}
|
||||
if constants.get("appointmentStatuses") != expected_appointment_statuses:
|
||||
got = constants.get("appointmentStatuses")
|
||||
raise ValueError(
|
||||
f"Appointment status mismatch in shared/constants.json. "
|
||||
f"Expected: {expected_appointment_statuses}, Got: {constants.get('appointmentStatuses')}"
|
||||
f"Appointment status mismatch. "
|
||||
f"Expected: {expected_appointment_statuses}, Got: {got}"
|
||||
)
|
||||
|
||||
|
||||
# Validate booking constants exist with required fields
|
||||
booking = constants.get("booking", {})
|
||||
required_booking_fields = ["slotDurationMinutes", "maxAdvanceDays", "minAdvanceDays", "noteMaxLength"]
|
||||
required_booking_fields = [
|
||||
"slotDurationMinutes",
|
||||
"maxAdvanceDays",
|
||||
"minAdvanceDays",
|
||||
"noteMaxLength",
|
||||
]
|
||||
for field in required_booking_fields:
|
||||
if field not in booking:
|
||||
raise ValueError(f"Missing booking constant '{field}' in shared/constants.json")
|
||||
|
||||
raise ValueError(f"Missing booking constant '{field}' in constants.json")
|
||||
|
||||
# Validate validation rules exist (structure check only)
|
||||
validation = constants.get("validation", {})
|
||||
required_fields = ["telegram", "signal", "nostrNpub"]
|
||||
for field in required_fields:
|
||||
if field not in validation:
|
||||
raise ValueError(f"Missing validation rules for '{field}' in shared/constants.json")
|
||||
raise ValueError(
|
||||
f"Missing validation rules for '{field}' in constants.json"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
validate_shared_constants()
|
||||
print("✓ Shared constants are valid")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue