Repository navigation
feat(rules): inline-tests moves inline tests over 30% of their file to a file of their own - #28
Draft
PiquelChips wants to merge 1 commit into
Draft
PiquelChips wants to merge 1 commit into
PiquelChips wants to merge 1 commit into
Conversation
3 tasks done
PiquelChips
force-pushed
the
feat/rule-childless-mod-rs
branch
from
November 22, 2026 22:11
bb21750 to
de9a425
Compare
…e of their own An inline #[cfg(test)] module at a file's top level spans at most 30% of the file's lines, in files a target reaches outside test code. --fix moves a larger one's body to tests.rs, dedented except inside string literals, leaves mod tests; in its place, moves foo.rs to foo/mod.rs when it needs a directory, and points relative include paths one directory up. childless-mod-rs counts the tests it moves out as a child. Fix gains line-range and create edits beside TOML edits and moves. The module walk records which files only test code reaches, and where a module's children live.
PiquelChips
force-pushed
the
feat/rule-inline-tests
branch
from
November 22, 2026 22:14
abdb91d to
6c41b93
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Unit tests belong in
#[cfg(test)] mod tests;with a siblingtests.rs(MT3). As the owner decided, an inline test module may stay only while it makes up at most 30% of its file. piqueld and DirkEngine each list a deviation for inline test blocks, and nothing checks the rule.inline-testsfails on a larger one, and--fixmoves it out.#[cfg(test)]module (anycfgrequiringtest, such asall(test, unix)) at the top level of a file that some target reaches outside test code, according to the base's module walk. Its lines run from its first attribute to its closing brace, compared with the file's line count. The rule skips integration tests, files only test code reaches, and generated files.--fixworks when the braces sit alone at the ends of their lines (rustfmt's layout):<module>.rsin the module's directory, with the module's indentation removed. Lines inside a multi-line string literal keep theirs.mod tests;takes the body's place, keeping the attributes.foo.rsfirst moves tofoo/mod.rs, asself_named_module_filesrequires. Relative paths ininclude!,include_str!andinclude_bytes!then gain a../: piqueld has one.lib.rs/main.rs(src/bin/tool.rs) gets no fix, since itstests.rswould become a target of its own.cargo fmtafterwards reflows lines the move made shorter.childless-mod-rs(feat(rules): childless-mod-rs moves a mod.rs without children to foo.rs #20) counts the tests this rule moves out as a child, so the two fixes don't fight over a childlessmod.rs.Fix: itsEditgains line-range and create variants beside the TOML edits and moves. The createdtests.rsnames its source file as what it resolves, so a deviation scoped to that file blocks the whole move.Modulesnow records which files only test code reaches (integration tests, benchmarks, modules behind a testcfg). It exposesModules::child_dir, which the walk and this fix share.test_code::TestAttributesreadscfg(test).Stacked on #20.
Testing
just check-changed feat/rule-childless-mod-rspasses, and re-measuring gives the counts below again.foo.rsand a childlessmod.rsfail, each with an oversized test module. So does a one-linecfg(all(test, unix))module inlib.rs.fixmoves both multi-line modules: the literal's line keeps its indentation, and theinclude_str!path gains../. The one-line module stays a violation.Measured with
rules::report, read-only, on detached worktrees of each repository'sorigin/main(since removed). The fix was applied togit archivecopies:--fixa17710f52e99cc0e6b07e8ba4430% is practical: it flags fewer modules than the 100-line fallback in piqueld and DirkEngine, and
--fixmoves every one. On the fixed copies,cargo check --testspasses for piqueld-core (including theinclude_str!case), piqueld-config, piquelctl, dirk_proc, dirk_utils and dirk_threads.rustfmt --checkshows only line reflows. Once this lands, piqueld's and DirkEngine's inline-test deviations can go.Checklist
just readme, and--fix's list in Commands.)Rulevariant; no xtask change.)just check-changedpasses.Note
Written by Claude Opus 5.5 in Claude Code (via T3 Code)