Skip to content

fix(lint): apply max-lines to .mts and .cts files - #21792

Closed
DeryFerd wants to merge 1 commit into
stablyai:mainfrom
DeryFerd:fix/max-lines-ratchet-cover-mts-cts
Closed

DeryFerd wants to merge 1 commit into
stablyai:mainfrom
DeryFerd:fix/max-lines-ratchet-cover-mts-cts

Conversation

@DeryFerd

Copy link
Copy Markdown
Contributor

ELI5

The repository caps how long a source file may grow and fails CI when a new file goes over, but the cap only ever looked at .ts, .tsx, and .mjs files. A file named .mts or .cts was invisible to both the linter rule and the ratchet that freezes its exceptions, so someone could move an oversized module to one of those extensions and the gate would stay green. This change makes both layers treat .mts and .cts the same way they already treat .ts.

What Changed

.oxlintrc.json now lists **/*.mts and **/*.cts alongside **/*.ts in the max-lines override at 300 lines, and the test/spec override grows from four globs to eight so **/*.test.mts, **/*.test.cts, **/*.spec.mts, and **/*.spec.cts get the same 800-line budget as their .ts counterparts.

config/scripts/check-max-lines-ratchet.mjs extends the git ls-files pattern from ['*.ts', '*.tsx', '*.mjs'] to ['*.ts', '*.tsx', '*.mts', '*.cts', '*.mjs'], so a new eslint-disable max-lines comment inside an .mts or .cts file is collected and compared against the baseline like any other file. defaultLimitForPath also learns the two extensions, which keeps the function's answer consistent with the linter for any path it is asked about.

The ratchet and the linter now agree on every TypeScript file type the repository actually ships, so switching an extension is no longer a way around the budget.

Why

The repository states the rule in AGENTS.md under "Lint Rules: Do Not Disable Max Lines", and pnpm lint enforces it through two independent pieces: oxlint's max-lines rule, and check:max-lines-ratchet, which freezes the set of files currently allowed to exceed the cap. Both pieces keyed off a hardcoded extension list. That list predates .mts/.cts files being added to the tree, and nothing forced it to grow when they arrived.

I confirmed the gap rather than inferring it. A generated 500-line .mts file passes oxlint --config .oxlintrc.json with zero errors, while an identical 500-line .ts file fails with Maximum allowed is 300. The same file renamed .mts reports nothing. That is the whole bug: the rule is correct, the file selection was not.

I chose to fix the selection rather than add a separate .mts-only rule, because a second rule would drift from the first. Extending the existing globs keeps one source of truth for what counts as a TypeScript file, and the ratchet's extension list now matches the linter's. The alternative I considered was scanning every tracked file and filtering by extension inside the script, but that would scan far more than needed and still leave oxlint's own glob list out of sync.

Linked Issue

No issue was provided for this request. The gap is reproducible from the current main with the two commands in the Testing section.

Visual Proof

N/A — this is a lint configuration and a Node script, with no UI or interaction change.

Testing

I verified the failing behavior first, then the fix, then that nothing else moved.

  • Wrote the tests before the change and watched them fail. defaultLimitForPath('a/b.test.mts') returned 300 instead of 800, and collectCurrentSuppressions returned only the .ts entry from a scratch tree that also contained an .mts and a .cts suppression.
  • Reproduced the underlying gap directly: a 500-line generated .mts passed oxlint with 0 errors before the change and fails with Maximum allowed is 300 after it. The same holds for .cts.
  • Confirmed the test/spec override still wins: a 400-line big.test.mts and a 400-line big.spec.cts both pass after the change, so the 800-line budget applies rather than the 300-line one.
  • pnpm test config/scripts/check-max-lines-ratchet.test.mjs — 18 passed (16 existing, 2 new).
  • pnpm test for the neighbouring ratchets (check-ts-nocheck-ratchet, check-runtime-electron-ratchet) — 35 passed across the three files.
  • pnpm check:max-lines-ratchet — exit 0, "7 grandfathered suppression(s), no new bypasses".
  • Whole-tree oxlint before and after the config change — 42 errors both times, identical set, so the new globs introduced no new findings. Zero max-lines errors come from any existing .mts or .cts file.
  • pnpm tc:node, pnpm tc:cli, pnpm tc:web — 0 TypeScript errors each.
  • oxfmt --check on the three changed files — clean.
  • lint-staged on the staged files — exit 0.

Platforms tested: Windows only for the local run. The change is pure file-extension matching with no platform branch, so macOS and Linux behave the same; CI covers all three.

AI Disclosure

ZCode with DeepSeek-V4.1-flash and GPT-5.6-Terra drafted the change, the tests, and this description. I reviewed the diff, reproduced the failure and the fix locally, and ran every command listed above before pushing.

Review

A quick self-review against the areas the contributing guide asks about.

Security: no change. The diff is a linter glob list, a Node script's git ls-files arguments, and a path-to-limit helper. No new input is parsed, no process is spawned, and no credential or network path is touched.

Cross-platform: no change. The code uses git ls-files and string suffix checks, both of which behave identically on macOS, Linux, and Windows. No path separator or shortcut handling is involved.

SSH/remote and local: not applicable. This is repository tooling that runs in CI and in the pre-commit hook; it does not execute on a remote host or read remote files.

Agent and integration compatibility: not applicable. No agent CLI, git provider, or integration code is involved.

Performance: neutral to slightly better in accuracy, no measurable cost. The ratchet reads at most four additional tracked files today (three .mts and one .cts exist in the tree), and oxlint applies one more override glob during its existing pass.

UI quality: not applicable, no UI.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

No issues in Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, or performance. The change is additive: every file that passed before still passes, because the new globs only add extensions that had no max-lines coverage at all. Backwards compatibility is safe in the strict sense too, since a stricter rule can only fail files that were previously uncapped, and no existing .mts or .cts file in the tree exceeds the budget.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

The `max-lines` rule and the ratchet that freezes its suppressions both
enumerated only `.ts`, `.tsx`, and `.mjs`. A contributor could therefore dodge
the file-size budget by switching a module's extension to `.mts` or `.cts`:
oxlint never applied `max-lines` to those files, and `collectCurrentSuppressions`
never scanned them, so a new suppression in one would not have been caught
either.

Extend the oxlint override globs (300 for `.mts`/`.cts`, 800 for their
test/spec variants) and the ratchet's `git ls-files` pattern to cover both
extensions, so the rule and its ratchet apply uniformly across TypeScript file
types.

Tests cover `defaultLimitForPath` for the new extensions and
`collectCurrentSuppressions` against a scratch git tree containing an `.mts`
and a `.cts` suppression.
@coderabbitai

coderabbitai Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 78cc2b90-054f-4a61-916d-c5f935d2a942

📥 Commits

Reviewing files that changed from the base of the PR and between e6aa90f and a633bc6.

📒 Files selected for processing (3)
  • .oxlintrc.json
  • config/scripts/check-max-lines-ratchet.mjs
  • config/scripts/check-max-lines-ratchet.test.mjs

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The Oxlint configuration now recognizes .mts and .cts files as TypeScript, including their test and spec variants. The max-lines ratchet applies TypeScript budgets to these extensions and scans them for inline suppression directives. Tests cover default budgets, suppression discovery, and files without suppressions.

Priority: ⬇️ Low

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: applying max-lines enforcement to .mts and .cts files.
Description check ✅ Passed The description is detailed and covers the required sections, including the change, reason, testing, compatibility review, and checklist. It explicitly states that no linked issue was provided, althou…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — verified the .mts/.cts gap is actually closed in both the linter config and the ratchet, and that the new tests fail without the fix.

  • .oxlintrc.json globs widened — **/*.mts/**/*.cts join the 300-line max-lines override, and the test/spec override gains the four .mts/.cts test/spec globs for its 800-line budget. That override is last in overrides[], so it wins for test/spec files.
  • Ratchet extension list widened — defaultLimitForPath now recognizes mts|cts (test/spec → 800, plain → 300), and collectCurrentSuppressions passes *.mts/*.cts to git ls-files, so a suppression added in either extension is collected against the baseline.
  • Tests added — new defaultLimitForPath cases plus a collectCurrentSuppressions suite that builds a scratch git repo and asserts .mts/.cts disables are found. Both are genuine: pre-change, defaultLimitForPath('a/b.test.mts') returned 300 and git ls-files omitted the two extensions.

I reproduced the behavior directly: a 500-line .mts/.cts now errors at 300, while 500-line .test.mts/.spec.cts pass at 800 (oxlint 1.80.0). pnpm test config/scripts/check-max-lines-ratchet.test.mjs (18 passed) and pnpm check:max-lines-ratchet (exit 0, 7 grandfathered) both pass. Only four tracked .mts/.cts files exist and none carries a disable, so the baseline is unaffected.

ℹ️ Extension-switch escape remains for .cjs/.js

This PR closes the loophole for the TypeScript family, but .mjs is the only JavaScript module extension with a budget (600 lines) — .cjs, .js, and .jsx have no max-lines override and are not scanned by the ratchet, so the same rename-to-dodge escape the PR describes still works there. That is pre-existing and may be deliberately out of scope for a TS-focused change; flagging only because the PR body's "switching an extension is no longer a way around the budget" reads as broader than what is fixed.

Technical details
# `.cjs`/`.js` remain uncapped

## Affected sites
- `.oxlintrc.json` overrides (`**/*.ts`/`.mts`/`.cts` → 300, `**/*.tsx` → 400, `**/*.mjs` → 600) — no entry covers `**/*.cjs`, `**/*.js`, or `**/*.jsx`.
- `config/scripts/check-max-lines-ratchet.mjs:99` — `git ls-files '*.ts' '*.tsx' '*.mts' '*.cts' '*.mjs'` omits `*.cjs`/`*.js`.
- Tracked examples: ~20 `.cjs` files under `config/scripts/` and `config/`, plus `mobile/*.js`, `native/windows-registry/index.js`.

## Required outcome
- Decide whether the gate is intentionally TypeScript-only. If so, the PR body's completeness claim is fine as prose but the asymmetry with `.mjs` (which is capped) is worth a comment. If the intent is to close the extension loophole generally, add the `*.cjs`/`*.js` equivalents to both the oxlint override and the ratchet's `git ls-files` list.

## Note
- Not a regression from this PR — the gap predates it. No change requested for this PR; this is a follow-up question.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

nwparker commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

thanks , I creidted you on #22413
!

@nwparker nwparker closed this Sep 25, 2026
@DeryFerd

Copy link
Copy Markdown
Contributor Author

Big thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants