Skip to content

feat(cli): add --max-file-size to skip large Markdown files (#81)#83

Merged
luojiyin1987 merged 3 commits into
masterfrom
feat/issue-81-max-file-size
Jul 9, 2026
Merged

feat(cli): add --max-file-size to skip large Markdown files (#81)#83
luojiyin1987 merged 3 commits into
masterfrom
feat/issue-81-max-file-size

Conversation

@luojiyin1987

Copy link
Copy Markdown
Contributor

Summary

  • Add a --max-file-size <size> CLI flag. Markdown files larger than the limit are skipped with a warning: skipped large Markdown file ... message written to stderr, and never reach lint/fix.
  • Format: b / kb/k / mb/m / gb/g (case-insensitive). Decimals (1.5mb), whitespace (1 mb), 0, negatives, and invalid strings are rejected with exit 1 + stderr, matching the --threads validation style.
  • Filtering happens after loadMdFiles() and before resolveAdaptiveConcurrency(), so --threads auto recomputes concurrency on the remaining files (the two are intentionally independent, per the issue).
  • When the flag is omitted, behavior is byte-for-byte unchanged. --fix also skips oversized files. Filtered-to-empty reuses the existing 🎉 No markdown files to lint 🎉 path.

Why this design

  • No new stat burst ([cli] getMaxFileSize: chunk stat calls or short-circuit on huge files #80 avoidance): filterFilesByMaxSize reuses runTasksWithLimit with the existing STAT_CONCURRENCY_LIMIT (128), so the per-file stat() pass is bounded exactly like getMaxFileSize. We deliberately did not add another unbounded Promise.all(stat).
  • Single responsibility: parse-size.ts parses/validates sizes; configure.ts#getMaxFileSizeOption does CLI validation + exit 1; filter-by-max-size.ts does the bounded scan + warning. The existing getMaxFileSize (real-max-size) is untouched.

Scope / non-goals

  • No .lintmdrc persistence, no --ignore-large-files flag, no default threshold (omit = unlimited).
  • lintMarkdown() public API unchanged.

Test plan

  • parse-size.spec.ts: unit tests for 500kb/1mb/5mb/1gb (+ case), and rejection of 1.5mb/1 mb/0/-1/abc.
  • max-file-size.spec.ts:
    • unit: over-limit dropped + stderr warning; all-kept; stat concurrency bounded to STAT_CONCURRENCY_LIMIT; stat failure propagates.
    • CLI (execFileSync): invalid size → exit 1; no flag → old behavior; oversized skipped (warning + not in report); --fix skips; all filtered → 🎉 message; --threads auto + filter on remaining files.
  • npm test (88 passed) and npm run lint green.

Closes #81

🤖 Generated with opencode

Add a --max-file-size <size> flag that drops Markdown files larger than
the limit (warning to stderr) before linting/fixing. Filtering reuses
runTasksWithLimit with STAT_CONCURRENCY_LIMIT so it does not reintroduce
the N-fd stat burst fixed in #80. --threads auto recomputes concurrency
on the remaining files; behavior is unchanged when the flag is omitted.
Replace formatMiB (always MiB) with formatBytes, which picks B / KiB /
MiB / GiB dynamically so sub-MiB thresholds no longer render as a
misleading "0 MiB".
Replace the permissive [bkmg]+ unit class (which accepted then rejected
kk/mbb) with an explicit b|k|kb|m|mb|g|gb alternation, matching the
issue's format definition. Drop the now-dead multiplier guard and add a
test pinning malformed-unit rejection.
@luojiyin1987 luojiyin1987 merged commit 284f417 into master Jul 9, 2026
5 checks passed
@luojiyin1987 luojiyin1987 deleted the feat/issue-81-max-file-size branch July 9, 2026 02:30
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.

[cli] 增加 max file size 和大文件处理策略

1 participant