From 22294ec5410e5b98808934d4d8a705b2548e3219 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Sat, 15 Aug 2026 22:42:57 +0200 Subject: [PATCH] Enforce the 250-line cap for real, and on Dart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) Claude-Session: https://claude.ai/code/session_01EveB813BQ8abAP68VSqZ5Y --- .pre-commit-config.yaml | 7 +++++-- scripts/check_file_length.py | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af6ba93..691cffc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/scripts/check_file_length.py b/scripts/check_file_length.py index cccbdcb..f709738 100755 --- a/scripts/check_file_length.py +++ b/scripts/check_file_length.py @@ -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