Repository navigation
ci: gate file size, function complexity and import cycles - #3765
jordan-simonovski wants to merge 5 commits into
Conversation
The 300-line file limit was only written down, and 239 source files are over it. The ratchet now fails when a file crosses 300 lines or a file already over it grows. oxlint warns on long or complex functions, deep nesting, long parameter lists, nested ternaries and import cycles, with each package's warning limit set to today's count so it cannot rise. The lint job writes a summary of file sizes and warnings by rule to the run page so the totals are visible while they are worked down.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Additional context: touches background tasks or the delivery pipeline lightly (27 lines, under the 30-line bar for Tier 4), 1 file(s) in private internal-tooling packages, excluded from the line count Review process: Full human review — logic, architecture, edge cases. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
| } | ||
|
|
||
| /** A baselined file that is gone, or now under the limit, and was at least this long. */ | ||
| function movedFrom(lines, current, baseline) { |
There was a problem hiding this comment.
🟡 P2 — movedFrom accepts any new large file as a 'move' if some unrelated baselined file has dropped out and was at least as long
movedFrom matches on line count alone. It also treats a file that shrank under 300 lines as a move source. Shrinkage is only a warning (compareSizes line 177), so stale entries stay in the committed baseline. Any later PR can then add an unrelated new file, for example a 900-line one while fixtures.ts: 1010 is stale, and plain yarn ratchet:update records it without --allow-growth. One source can also license any number of new files. Fix: require a real link to the source, such as the same basename or the source deleted in this diff, and consume each source once, or limit the parts' total to the source's size. Add a test where an unrelated new file and a stale entry exist together.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Fixed in d342943, same change as the P1 thread: sources must be deleted, each is consumed by line count, and a same-named source is preferred. Not requiring a matching basename, since splitting a file into differently named parts is the case this exists for.
PR Review
4 finding(s): 🔴 0 P0/P1 · 🟡 3 P2 · 🔵 1 P3 3 posted as inline comment(s) on the changed lines. 1 P3 folded at the bottom. 🔵 1 P3 — no action needed before merge
Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical issues found. This is CI tooling (ratchet scripts, oxlint config, a workflow step) with no production code path. The core move/split budget logic ( 🟡 P2 — recommended
🔵 P3 nitpicks (5)
Reviewers (6): correctness, reliability, testing, maintainability, security, project-standards, previous-comments. (The correctness and adversarial personas were dispatched but did not return before synthesis; the orchestrator's own analysis of the move-budget logic, Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
E2E Test Results❌ 1 test failed • 476 passed • 1 skipped • 1086s
Tests ran across 4 shards in parallel. |
The report was only on the run summary page, which nobody opens. The lint job now posts it as one comment per PR, updated on each push, with the tables collapsed.
Code quality report
|
A baselined file that shrank under 300 lines, or any unrelated deleted file, let a new oversized file through plain ratchet:update. A source now has to be gone from disk and covers new files only up to its own line count. Also builds common-utils before the quality report so its type-aware counts match what ci:lint gates on.
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write |
There was a problem hiding this comment.
🟡 P2 — The whole lint job now gets pull-requests: write, though only the last comment step needs it
Every step in the job runs with a token that can write to PRs, including yarn install lifecycle scripts, nx tasks and PR-authored scripts, and so do push runs, which never comment. Only the comment step needs that scope. Fix: drop pull-requests: write from lint, upload quality-comment.md as an artifact, and post it from a small follow-up job (needs: lint, if: github.event_name == 'pull_request') that alone has pull-requests: write.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
Warning limits recounted on top of main's lower ones (api 309, app 785), and the file size baseline refreshed for files that changed on main. Concluding a merge no longer fails pre-commit on warnings in lines that came in unchanged from the other parent.
| id: quality | ||
| if: always() | ||
| continue-on-error: true | ||
| timeout-minutes: 3 |
There was a problem hiding this comment.
🟡 P2 — The 'advisory' quality report can still time out and fail the whole lint job
continue-on-error and the step's 3-minute timeout-minutes do not protect against the job's timeout-minutes: 8 (line 12). If the job runs past 8 minutes, GitHub fails the job, not just the step. This step rebuilds common-utils and then runs a second type-aware oxlint over all five packages, after ci:lint has already linted them (on push runs, every package via run-many). That can add up to 3 minutes to the job. If the limit is hit, the advisory report turns the lint job red, and on push runs it also skips Save nx computation cache (line 105). Fix: raise the job timeout by the step's budget, or move the report into its own job so it cannot affect the gating job.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| # --max-warnings. This only makes the totals visible on the run page. | ||
| - name: Code quality report | ||
| id: quality | ||
| if: always() |
There was a problem hiding this comment.
🟡 P2 — if: always() keeps the report running after the run is cancelled
The workflow sets concurrency.cancel-in-progress: true, so a new push cancels the old run. always() still runs on cancellation, so the cancelled run keeps rebuilding common-utils and linting every package for up to 3 minutes, holding the runner. The comment step at line 90 has the same problem. Fix: use !cancelled() in both conditions.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| for (const [file, max] of Object.entries(baseline)) { | ||
| if ((current[file] ?? 0) < max) { | ||
| messages.push( | ||
| `! ${file}: ${current[file] ?? `under ${MAX_FILE_LINES + 1}`} lines < baseline ${max} — run \`yarn ratchet:update\` to lock the improvement in`, |
There was a problem hiding this comment.
🟡 P2 — A deleted or moved file is reported as 'under 301 lines'
When a baselined file is gone from disk (moved or split), current[file] is undefined, so the second loop prints ! a.ts: under 301 lines < baseline 500. That sits next to the moved or split from a.ts error and tells the contributor the file still exists and shrank. Fix: pass exists into this branch and print deleted / moved when !exists(file), keeping under 301 for files that really shrank.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
Summary
The 300-line file limit only existed as a sentence in the docs, and 239 source files are over it, nine of them past 2,000 lines. This makes the limit, and a set of function-level limits, something CI enforces, so the numbers stop rising while they are worked down.
Outcomes
.d.tsfiles are exempt.yarn ratchet:update.Behaviour changes for contributors
yarn ratchet:update --allow-growthand says why. Plainyarn ratchet:updateonly records files that shrank or moved.cliandhdx-evalhad a warning limit of 0. They now sit at 74 and 44, the count the new rules find today.Key decisions
Known limits
mainuntil one is fixed. 22 files sit between 281 and 300 lines.How to reproduce
Starting point: a checkout of this branch,
yarn installdone.On
main:packages/api/src/utils/zod.ts(1,494 lines).yarn ratchet. It passes.On this branch:
packages/api/src/utils/zod.ts.yarn ratchet. It fails with1495 lines > baseline 1494.yarn ratchet:update. It refuses to record the growth.node scripts/ci/quality-report.mjsto see the report the lint job publishes.How to test on Vercel preview
N/A, non-UI change.