P0020 commit-mixed-move¶
Rule: A commit that moves a file does not also edit it beyond its paths.
| Code | P0020 (stable, never reused) |
| Id | commit-mixed-move |
| Category | commits |
| Source | spirit_level |
| Fix | by hand |
| Needs | git installed |
Level per tier¶
| Tier | Level | Reason |
|---|---|---|
| small | off | |
| small-workspace | off | |
| medium | off | |
| big | off | |
| ai | warn |
a move edited in the same commit cuts every line's history; a warning, since it judges lines by their start |
| embedded | off | |
| ui | off | |
| egui | off | |
| units-strict | off | |
| units-paranoid | off |
Parameters¶
| Name | Type | Default | Meaning |
|---|---|---|---|
files |
list of strings | ["**/*.rs"] |
globs of the moved files checked |
path-lines |
list of strings | ["use ", "pub use ", "pub(crate) use ", "mod ", "pub mod ", "pub(crate) mod ", "#[path", "//!"] |
starts of changed lines that only follow the move |
base |
string | "main" |
the branch work merges into; commits in base..HEAD are checked |
Why¶
git shows a moved file as a move only while its content stays nearly the same. A move edited in the same commit shows as a deletion and a new file: the history of every line is cut, and a reviewer cannot tell the move from the change. Moving in one commit and editing in the next keeps both readable.
The lint looks at each file of files (Rust sources) that git finds renamed in a commit of the branch with changes. Changed lines that only follow the move (use, mod, #[path], lines naming crate::, super:: or self:: paths) are allowed; any other changed line makes a finding. The line judgement is an estimate.
How to fix¶
Split the commit: first the move with the path changes it needs, then the edit. On the branch, an interactive rebase or a reset and two commits does it.
Configure¶
[lints.commit-mixed-move]
level = "deny"
files = ["**/*.rs"]
path-lines = ["use ", "pub use ", "pub(crate) use ", "mod ", "pub mod ", "pub(crate) mod ", "#[path", "//!"]
base = "main"
reason = "why this project wants it at this level"
Allow one finding in the code with // spirit-level: allow(commit-mixed-move) <reason> (waivers); the code works there too, as in [lints.P0020].