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