Skip to content

Conversation

@andrewgazelka
Copy link

Changes

  • Added new EXCESSIVE_FILE_LENGTH lint (restriction, allow-by-default)
  • Added excessive-file-length-threshold configuration option (default: 500 lines)
  • The lint checks all source files in the local crate during check_crate
  • Added UI tests demonstrating the lint behavior
  • Updated CHANGELOG.md with the new lint link

Configuration

Users can configure the threshold in clippy.toml:

excessive-file-length-threshold = 500

Setting the threshold to 0 disables the lint.

Rationale

Large files can be harder to navigate and understand. This lint helps identify files that might benefit from being split into smaller, more focused modules, improving maintainability.

Testing

Added test case in tests/ui-toml/excessive_file_length/ with:

  • clippy.toml setting threshold to 10 lines
  • Test file with 16 lines that triggers the lint
  • Expected .stderr output

changelog: [excessive_file_length]: new restriction lint to warn about files exceeding a configurable line count threshold

@github-actions
Copy link

Lintcheck changes for 52f7ad0

Lint Added Removed Changed
clippy::excessive_file_length 664 0 0

This comment will be updated if you push new changes

None,
);

span_lint_and_help(
Copy link
Member

Choose a reason for hiding this comment

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

You should use span_lint_hir_and_then here, that way you can use #[expect] & #[allow]. Now getting an HirId might be a bit tricky. If you can, maybe use the HirId of the mod item?

Copy link
Member

Choose a reason for hiding this comment

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

You could probably use a Visitor to search the HIR before linting, either in check_crate + check_crate_post or in the same fn (just check_crate). From there you just store each module definition's name & HirId. There are other ways but AFAIK this should be the simplest.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, it'd be quicker to just use check_item + check_crate_post

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants