Enforce the 250-line cap for real, and on Dart
Some checks are pending
pre-commit / pre-commit (push) Waiting to run
Tests / test (3.10) (push) Waiting to run
Tests / test (3.11) (push) Waiting to run
Tests / test (3.12) (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
release-apk / release (APK) (push) Waiting to run

The gate this whole refactor was aimed at had two holes:

- `MAX_LINES` was 400, while `refresh_refactor_todo.py` reported against 250.
  The hook and the TODO generator disagreed about what "over the cap" meant.
- `types_or` was [python, shell], so the hook had never inspected a single
  Dart file. Every file in the refactor — workout_screen.dart at 633 lines
  included — was exempt from the check it was being split to satisfy.

A violation also exited 1 while printing nothing, so a developer got a failed
commit with no indication of which file or by how much. It now names the file
and the overage on stderr.

Verified by planting a 260-line Dart file: the hook exits 1 and reports it.
Boundary checked at 250 (pass) / 251 (fail).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EveB813BQ8abAP68VSqZ5Y
This commit is contained in:
Krzysztof Rudnicki 2026-08-15 22:42:57 +02:00
parent a7ca5bfbb4
commit 22294ec541
2 changed files with 19 additions and 3 deletions

View File

@ -184,10 +184,13 @@ repos:
language: system
types: [shell]
- id: max-file-length
name: Max file length (400 lines)
name: Max file length (250 lines)
entry: python3 scripts/check_file_length.py
language: system
types_or: [python, shell]
# Dart was missing here until 2026-08-15, so the cap had never looked at
# a single file in workout_app/ — the whole Flutter app was exempt from
# the gate it was being refactored to satisfy.
types_or: [python, shell, dart]
- id: no-silent-failures
name: Block silent failures (swallowed exceptions must log why)
entry: python3 scripts/check_silent_failures.py

View File

@ -4,13 +4,17 @@
import logging
import sys
MAX_LINES = 400
MAX_LINES = 250
_logger = logging.getLogger(__name__)
def main() -> int:
"""Return 1 if any file exceeds the line limit, else 0."""
# Without this the module relies on logging's last-resort handler, which
# drops anything below WARNING and prints no context — a hook that fails
# without saying which file is a silent failure.
logging.basicConfig(format="%(levelname)s: %(message)s", stream=sys.stderr)
failed = False
for filepath in sys.argv[1:]:
try:
@ -27,6 +31,15 @@ def main() -> int:
failed = True
continue
if count > MAX_LINES:
# A bare non-zero exit tells nobody which file blew the cap, so the
# violation has to name itself and the size of the split it needs.
_logger.error(
"%s is %d lines — %d over the %d-line cap. Split it before committing.",
filepath,
count,
count - MAX_LINES,
MAX_LINES,
)
failed = True
return 1 if failed else 0