Skip to content

S0004 module-lines

Rule: A source file stays under its line limit.

Code S0004 (stable, never reused)
Id module-lines
Category size
Source spirit_level
Fix by hand

Level per tier

Tier Level Reason
small off
small-workspace off
medium warn a file of thousands of lines holds several subjects and collects every edit
big warn a file of thousands of lines holds several subjects and collects every edit
ai off
embedded off
ui off
egui off
units-strict off
units-paranoid off

Parameters

Name Type Default Meaning
max-lines integer 1000 code lines of one file above which it is reported

Why

A source file of thousands of lines holds several subjects; reviews, merges and readers suffer first. tpm_cli's main.rs of 8,700 lines changed in 67% of all landings because it held every command's clap types.

How to fix

Split the module by subject: a type and its impls, a command, a parser each in a file of its own.

Configure

[lints.module-lines]
level = "deny"
max-lines = 1000
reason = "why this project wants it at this level"

Allow one finding in the code with // spirit-level: allow(module-lines) <reason> (waivers); the code works there too, as in [lints.S0004].