Repository navigation
ci: gate file size, function complexity and import cycles - #3765
jordan-simonovski wants to merge 4 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. 2 Skipped Deployments
|
|
🟡 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
3 finding(s): 🔴 0 P0/P1 · 🟡 2 P2 · 🔵 1 P3 1 posted as inline comment(s) on the changed lines. 1 listed below. 1 P3 folded at the bottom. Findings outside the changed lines
🔵 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 a well-constructed CI-tooling change: the ratchet logic is sound, the advisory report step is correctly isolated from the gate ( 🟡 P2 — recommendedNone. 🔵 P3 nitpicks (2)
Reviewers (5): security, correctness, maintainability, testing, previous-comments. 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✅ All tests passed • 471 passed • 1 skipped • 1065s
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.
| } | ||
|
|
||
| /** 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.
🔴 P1 — movedFrom counts a file that shrank under 300 lines as a move source, so plain ratchet:update accepts new oversized files
movedFrom treats any baseline file missing from current as the place a file moved from. current only lists files over 300 lines, so a file that still exists but dropped to 300 lines or fewer also counts. Example: a PR trims packages/app/src/ChartUtils.tsx (baseline 1612) to 290 lines and grows an unrelated new foo.ts to 1500 lines. CI says "moved or split from ChartUtils.tsx", and nextSizeBaseline records foo.ts without --allow-growth. A single freed entry can also license any number of new files at once. Only count baseline paths that no longer exist on disk (pass the set of existing files, or check existsSync), and let each source cover at most the line total it freed. Add a test where the source file still exists but shrank.
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond
There was a problem hiding this comment.
Fixed in d342943: a move source must now be gone from disk, and it covers new files only up to its own line count. Tests added for a shrunk-but-present source and for one source split across several files.
| run: node scripts/ci/ratchet.mjs | ||
| # Advisory: the gates are the ratchet above and each package's | ||
| # --max-warnings. This only makes the totals visible on the run page. | ||
| - name: Code quality report |
There was a problem hiding this comment.
🟡 P2 — Quality report runs type-aware oxlint on every package, but upstream dist is only built for affected projects
The lint step uses nx affected, so on a PR that touches no package (docs or CI only) common-utils is never built. The report then lints all five packages type-aware with @hyperdx/common-utils/dist/* unresolved. The comment can post counts that don't match what ci:lint gates against each --max-warnings limit. Fix: build common-utils before this step, or report only the packages nx affected linted. Two more risks: it runs under if: always() after a failed install, and the 2-minute timeout covers five type-aware runs.
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: the report step builds common-utils first, and its timeout is 3 minutes. Left if: always(): a failed install makes the step fail, which continue-on-error absorbs and which skips the comment.
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
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.