rust-lang / rust-lang/rust-clippy
New lint: `too_many_lines_in_file` — warn when a source file exceeds a configurable line count
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Warns when a source file contains more lines of code than a configurable threshold. Comment-only lines and blank lines would be excluded from the count (mirroring the behavior of too_many_lines for functions).
Advantage
- Encourages splitting large files into smaller, more focused modules
- Complements the existing
too_many_lineslint, which operates at the function level, by also enforcing hygiene at the file/module level - Large files are often a sign of poor separation of concerns and can hurt navigability and reviewability
Drawbacks
- This is inherently a style/restriction lint — reasonable threshold values vary widely by project
- Some files (e.g. generated code, large lookup tables) legitimately need to be long; users would need to suppress the lint for those
- Could be noisy on large existing codebases if adopted without tuning the threshold
Example
This lint fires on a file as a whole rather than a specific expression, so there is no before/after code rewrite. The diagnostic would look like:
warning: this file has too many lines (1200/1000)
--> src/my_module.rs:1:1
|
1 | // src/my_module.rs
| ^
= help: consider splitting the module into smaller submodules
The intended fix is to split the file into smaller, more focused modules.
Comparison with existing lints
too_many_lines— lints on individual functions exceeding a line threshold. This proposed lint operates at the file level, which is a coarser and complementary granularity.- No existing Clippy lint checks overall file length.
Additional Context
- Should belong to the
restrictiongroup (opt-in), similar totoo_many_lines - The threshold should be configurable via
clippy.toml, e.g.too-many-lines-in-file-threshold = 1000(default could be 1000) - Counting logic should match
too_many_lines: skip blank lines and comment-only lines, count only lines with actual code
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing too_many_lines lint and its restriction-group and configuration tests; the issue names no implementation files or test paths. Done means a file-level lint supports the proposed configurable threshold, skips blank and comment-only lines, emits the described diagnostic, and has coverage for the counting and configuration behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100