Skip to content

New lint: too_many_lines_in_file#16675

Open
tupe12334 wants to merge 1 commit intorust-lang:masterfrom
tupe12334:too-many-lines-in-file
Open

New lint: too_many_lines_in_file#16675
tupe12334 wants to merge 1 commit intorust-lang:masterfrom
tupe12334:too-many-lines-in-file

Conversation

@tupe12334
Copy link

@tupe12334 tupe12334 commented Mar 6, 2026

Closes #16674

Summary

Adds a new restriction lint too_many_lines_in_file that warns when a source file exceeds a configurable number of lines of code. Blank lines and comment-only lines are not counted, matching the behavior of the existing too_many_lines function-level lint.

Configuration

too-many-lines-in-file-threshold in clippy.toml (default: 1000)

Example diagnostic

warning: this file has too many lines (1200/1000)
  --> src/my_module.rs:1:1
   |
 1 | // src/my_module.rs
   | ^

Implementation notes

  • Uses an EarlyLintPass with check_crate, iterating all source files in the session source map
  • Filters to local crate files only (file.cnum == LOCAL_CRATE) to avoid checking dependencies
  • Line counting logic mirrors too_many_lines: skips blank lines and comment-only lines (including /* */ block comments)
  • Span points to file.start_pos (line 1, col 1 of the file)

Disclosure

The code in this PR was generated with the assistance of Claude Code, Anthropic's AI coding assistant.

changelog: new lint: [too_many_lines_in_file]

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Mar 6, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2026

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@rustbot

This comment has been minimized.

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

Lintcheck changes for 2c4c95a

Lint Added Removed Changed
clippy::too_many_lines_in_file 154 0 0

This comment will be updated if you push new changes

Adds a new `restriction` lint that warns when a source file exceeds a
configurable number of lines of code. Blank lines and comment-only lines
are excluded from the count, mirroring the behavior of `too_many_lines`.

The span points to the specific line where the threshold is exceeded,
giving a more actionable location in the diagnostic.

The threshold is configurable via `too-many-lines-in-file-threshold` in
`clippy.toml` (default: 1000).

Closes rust-lang#16674

changelog: new lint: [`too_many_lines_in_file`]
@tupe12334 tupe12334 force-pushed the too-many-lines-in-file branch from 4f0e1fb to 2c4c95a Compare March 6, 2026 12:05
@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2026

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

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

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New lint: too_many_lines_in_file — warn when a source file exceeds a configurable line count

3 participants