-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels