Add a per-method length ratchet (max 150 lines, AST-measured) #51

Merged
brenno merged 1 commit from chore/method-length-ratchet into main 2026-06-30 17:30:53 +00:00
Owner

Sets up the per-method length ratchet — the per-declaration sibling of the file-size ratchet — and captures today's offenders as a baseline. This PR is the gate only; no methods are refactored yet (those follow one per PR, lowering their baseline entry, exactly like the file splits did).

What it does

tool/check_method_length.dart walks every .dart file in lib/ and fails when a method, top-level function or constructor body exceeds 150 lines — except the declarations listed in methodLengthBaseline, whose ceiling is their current length and may only shrink, never grow.

  • AST-measured via the analyzer package (not a brace heuristic), so closures, multi-line signatures and => bodies are counted correctly. Keys are path::Enclosing.name, stable across line edits; local functions count toward their enclosing method.
  • 28 declarations are over 150 today and are baselined, so the tree is green. The biggest:
lines declaration
680 _MainLayoutState.build
447 _MarkdownParse._parseBlock
341 MarkdownService.generateSlide
313 _PreviewPanelState.build
312 SlideThumbnail.build

A new long method, or growth of a baselined one, now fails CI.

Wiring

  • analyzer added as a direct dev_dependency, pinned to the resolved 12.1.0 (lockfile updated for CI's --enforce-lockfile).
  • new make check-method-length target, added to the make check aggregate and as a CI step next to check-conventions.
  • documented in docs/CHECKS.md (glance table + detail section).

Verification

  • dart run tool/check_method_length.dartgreen (max 150, 28 baselined); fails with the full list when the baseline is emptied, confirming detection works.
  • flutter analyze --fatal-infos on the tool — clean.
  • dart format — clean.

What's next (not in this PR)

Split the worst offenders one per PR — starting with the pure-logic monsters that have the strongest test nets (generateSlide, _parseBlock — round-trip/fuzz/mutation), then the build() methods via sub-widget extraction (golden-covered) — lowering each baseline entry as we go.

Sets up the **per-method length ratchet** — the per-declaration sibling of the file-size ratchet — and captures today's offenders as a baseline. **This PR is the gate only; no methods are refactored yet** (those follow one per PR, lowering their baseline entry, exactly like the file splits did). ### What it does `tool/check_method_length.dart` walks every `.dart` file in `lib/` and fails when a method, top-level function or constructor body exceeds **150 lines** — except the declarations listed in `methodLengthBaseline`, whose ceiling is their current length and **may only shrink, never grow**. - **AST-measured** via the `analyzer` package (not a brace heuristic), so closures, multi-line signatures and `=>` bodies are counted correctly. Keys are `path::Enclosing.name`, stable across line edits; local functions count toward their enclosing method. - **28 declarations** are over 150 today and are baselined, so the tree is green. The biggest: | lines | declaration | |---|---| | 680 | `_MainLayoutState.build` | | 447 | `_MarkdownParse._parseBlock` | | 341 | `MarkdownService.generateSlide` | | 313 | `_PreviewPanelState.build` | | 312 | `SlideThumbnail.build` | A new long method, or growth of a baselined one, now fails CI. ### Wiring - `analyzer` added as a **direct `dev_dependency`**, pinned to the resolved `12.1.0` (lockfile updated for CI's `--enforce-lockfile`). - new `make check-method-length` target, added to the `make check` aggregate and as a CI step next to `check-conventions`. - documented in `docs/CHECKS.md` (glance table + detail section). ### Verification - `dart run tool/check_method_length.dart` — **green** (max 150, 28 baselined); fails with the full list when the baseline is emptied, confirming detection works. - `flutter analyze --fatal-infos` on the tool — clean. - `dart format` — clean. ### What's next (not in this PR) Split the worst offenders one per PR — starting with the pure-logic monsters that have the strongest test nets (`generateSlide`, `_parseBlock` — round-trip/fuzz/mutation), then the `build()` methods via sub-widget extraction (golden-covered) — lowering each baseline entry as we go.
Add a per-method length ratchet (max 150 lines, AST-measured)
Some checks failed
CI / Web hardening (push) Has been cancelled
CI / Docs links (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Gate (Linux) · Format · Analyze · Coverage (push) Has been cancelled
CI / Test (macos-latest) (push) Has been cancelled
CI / Gate (Linux) · Format · Analyze · Coverage (pull_request) Has been cancelled
CI / Test (macos-latest) (pull_request) Has been cancelled
CI / Test (windows-latest) (pull_request) Has been cancelled
CI / Web hardening (pull_request) Has been cancelled
CI / Docs links (pull_request) Has been cancelled
0f7e4e93e6
The per-declaration sibling of the file-size ratchet. tool/check_method_
length.dart measures every method, top-level function and constructor body
with the analyzer's AST (so closures, multi-line signatures and => bodies
count correctly) and fails when one exceeds 150 lines — except the
declarations in methodLengthBaseline, whose ceiling is their current length
and may only shrink.

This commit is the gate only: the 28 declarations already over 150 are
captured in the baseline (largest: _MainLayoutState.build at 680,
_parseBlock at 447, generateSlide at 341), so the tree is green. New long
methods, or growth of a baselined one, now fail. Follow-up PRs split the
worst offenders and lower their entries — same cadence as the file splits.

- analyzer added as a direct dev_dependency (pinned to the resolved 12.1.0)
- wired into `make check` + a `check-method-length` target and the CI job
- documented in docs/CHECKS.md
brenno merged commit b659ff58e7 into main 2026-06-30 17:30:53 +00:00
brenno deleted branch chore/method-length-ratchet 2026-06-30 17:30:53 +00:00
Sign in to join this conversation.
No description provided.