feat(validators): add noqa suppression support to security and performance validators
All checks were successful
CI / dependency-scanning (push) Successful in 27s
CI / docs (push) Successful in 35s
CI / ruff (push) Successful in 8s
CI / pytest (push) Successful in 34m22s
CI / validate (push) Successful in 19s
CI / deploy (push) Successful in 2m25s

- Add centralized _is_noqa_suppressed() to BaseValidator with normalization
  (accepts both SEC001 and SEC-001 formats for ruff compatibility)
- Wire noqa support into all 21 security and 18 performance check functions
- Add ruff external config for SEC/PERF/MOD/EXC codes in pyproject.toml
- Convert all 280 Python noqa comments to dashless format (ruff-compatible)
- Add site/ to IGNORE_PATTERNS (excludes mkdocs build output)
- Suppress 152 false positive findings (test passwords, seed data, validator
  self-references, Apple Wallet SHA1, etc.)
- Security: 79 errors → 0, 60 warnings → 0
- Performance: 80 warnings → 77 (3 test script suppressions)
- Add proposal doc with noqa inventory and remaining findings recommendations

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 22:56:56 +01:00
parent f84c5d903e
commit 1b8a40f1ff
75 changed files with 404 additions and 310 deletions

View File

@@ -29,18 +29,18 @@ from app.modules.tenancy.models import Store
def generate_order_number():
"""Generate a realistic Letzshop order number like R532332163."""
return f"R{random.randint(100000000, 999999999)}"
return f"R{random.randint(100000000, 999999999)}" # noqa: SEC042
def generate_shipment_number():
"""Generate a realistic shipment number like H74683403433."""
return f"H{random.randint(10000000000, 99999999999)}"
return f"H{random.randint(10000000000, 99999999999)}" # noqa: SEC042
def generate_hash_id():
"""Generate a realistic hash ID like nvDv5RQEmCwbjo."""
chars = string.ascii_letters + string.digits
return "".join(random.choice(chars) for _ in range(14))
return "".join(random.choice(chars) for _ in range(14)) # noqa: SEC042
def create_dummy_order(
@@ -96,19 +96,19 @@ def create_dummy_order(
order_number = generate_order_number()
shipment_number = generate_shipment_number()
hash_id = generate_hash_id()
order_date = datetime.now(UTC) - timedelta(days=random.randint(0, 7))
order_date = datetime.now(UTC) - timedelta(days=random.randint(0, 7)) # noqa: SEC042
# Customer data
first_names = ["Jean", "Marie", "Pierre", "Sophie", "Michel", "Anne", "Thomas", "Claire"]
last_names = ["Dupont", "Martin", "Bernard", "Dubois", "Thomas", "Robert", "Richard", "Petit"]
cities = ["Luxembourg", "Esch-sur-Alzette", "Differdange", "Dudelange", "Ettelbruck"]
customer_first = random.choice(first_names)
customer_last = random.choice(last_names)
customer_first = random.choice(first_names) # noqa: SEC042
customer_last = random.choice(last_names) # noqa: SEC042
customer_email = f"{customer_first.lower()}.{customer_last.lower()}@example.lu"
# Calculate totals in cents
subtotal_cents = sum((p.price_cents or 0) * random.randint(1, 3) for p in products[:items_count])
subtotal_cents = sum((p.price_cents or 0) * random.randint(1, 3) for p in products[:items_count]) # noqa: SEC042
shipping_cents = 595 # €5.95
total_cents = subtotal_cents + shipping_cents
@@ -118,7 +118,7 @@ def create_dummy_order(
customer_id=1, # Placeholder customer ID
order_number=f"LS-{store_id}-{order_number}",
channel="letzshop",
external_order_id=f"gid://letzshop/Order/{random.randint(10000, 99999)}",
external_order_id=f"gid://letzshop/Order/{random.randint(10000, 99999)}", # noqa: SEC042
external_order_number=order_number,
external_shipment_id=hash_id,
shipment_number=shipment_number,
@@ -134,25 +134,25 @@ def create_dummy_order(
customer_first_name=customer_first,
customer_last_name=customer_last,
customer_email=customer_email,
customer_phone=f"+352 {random.randint(600000, 699999)}",
customer_phone=f"+352 {random.randint(600000, 699999)}", # noqa: SEC042
customer_locale="fr",
# Shipping address
ship_first_name=customer_first,
ship_last_name=customer_last,
ship_company=None,
ship_address_line_1=f"{random.randint(1, 200)} Rue du Test",
ship_address_line_1=f"{random.randint(1, 200)} Rue du Test", # noqa: SEC042
ship_address_line_2=None,
ship_city=random.choice(cities),
ship_postal_code=f"L-{random.randint(1000, 9999)}",
ship_city=random.choice(cities), # noqa: SEC042
ship_postal_code=f"L-{random.randint(1000, 9999)}", # noqa: SEC042
ship_country_iso="LU",
# Billing address (same as shipping)
bill_first_name=customer_first,
bill_last_name=customer_last,
bill_company=None,
bill_address_line_1=f"{random.randint(1, 200)} Rue du Test",
bill_address_line_1=f"{random.randint(1, 200)} Rue du Test", # noqa: SEC042
bill_address_line_2=None,
bill_city=random.choice(cities),
bill_postal_code=f"L-{random.randint(1000, 9999)}",
bill_city=random.choice(cities), # noqa: SEC042
bill_postal_code=f"L-{random.randint(1000, 9999)}", # noqa: SEC042
bill_country_iso="LU",
# Timestamps
order_date=order_date,
@@ -160,17 +160,17 @@ def create_dummy_order(
# Set status-specific timestamps
if status in ["processing", "shipped", "delivered"]:
order.confirmed_at = order_date + timedelta(hours=random.randint(1, 24))
order.confirmed_at = order_date + timedelta(hours=random.randint(1, 24)) # noqa: SEC042
if status in ["shipped", "delivered"]:
order.shipped_at = order.confirmed_at + timedelta(days=random.randint(1, 3))
order.shipped_at = order.confirmed_at + timedelta(days=random.randint(1, 3)) # noqa: SEC042
if status == "delivered":
order.delivered_at = order.shipped_at + timedelta(days=random.randint(1, 5))
order.delivered_at = order.shipped_at + timedelta(days=random.randint(1, 5)) # noqa: SEC042
if status == "cancelled":
order.cancelled_at = order_date + timedelta(hours=random.randint(1, 48))
order.cancelled_at = order_date + timedelta(hours=random.randint(1, 48)) # noqa: SEC042
# Add tracking if requested
if with_tracking or status == "shipped":
order.tracking_number = f"LU{random.randint(100000000, 999999999)}"
order.tracking_number = f"LU{random.randint(100000000, 999999999)}" # noqa: SEC042
order.tracking_provider = carrier
if carrier == "greco":
order.tracking_url = f"https://dispatchweb.fr/Tracky/Home/{shipment_number}"
@@ -180,7 +180,7 @@ def create_dummy_order(
# Create order items with prices in cents
for _i, product in enumerate(products[:items_count]):
quantity = random.randint(1, 3)
quantity = random.randint(1, 3) # noqa: SEC042
unit_price_cents = product.price_cents or 0
product_name = product.get_title("en") or f"Product {product.id}"
item = OrderItem(
@@ -193,7 +193,7 @@ def create_dummy_order(
quantity=quantity,
unit_price_cents=unit_price_cents,
total_price_cents=unit_price_cents * quantity,
external_item_id=f"gid://letzshop/InventoryUnit/{random.randint(10000, 99999)}",
external_item_id=f"gid://letzshop/InventoryUnit/{random.randint(10000, 99999)}", # noqa: SEC042
item_state="confirmed_available" if status != "pending" else None,
inventory_reserved=status != "pending",
inventory_fulfilled=status in ["shipped", "delivered"],