Repository navigation
feat(rules): inline-limits makes Durations with literals named constants - #30
Draft
PiquelChips wants to merge 1 commit into
Draft
PiquelChips wants to merge 1 commit into
PiquelChips wants to merge 1 commit into
Conversation
PiquelChips
force-pushed
the
feat/rule-inline-tests
branch
from
November 22, 2026 22:14
abdb91d to
6c41b93
Compare
Duration::from_* with a number, or arithmetic on numbers, sits only in a const or static item, a const fn or test code. A shared walk over each file's expressions tracks those scopes; test code spans test attributes, cfgs requiring test or a feature named for tests, and the files the module walk reaches only as test code.
PiquelChips
force-pushed
the
feat/rule-inline-limits
branch
from
November 22, 2026 22:16
4a8fa5d to
f1f4399
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
Limits, timeouts and sizes are named constants with a doc comment (TY5). Without a check,
tokio::time::timeout(Duration::from_secs(10), …)keeps appearing inline, where nobody can find or tune it.inline-limitsfails onDuration::from_*called with a number, or arithmetic on numbers, outside aconstorstaticitem, aconst fnand test code.missing_docsalready requires the constant's doc comment.const fncounts as constant: piqueld'sDockerTimeout::durationand its store's sync timeouts areconst fntables keyed by a documented enum, which already names each limit.Test code, which the next rules reuse:
#[test],#[tokio::test], any…::test);cfgrequiringtestor a feature named for tests marks (cfg(any(test, feature = "test-util")), sourceorigin's fixtures);Modules::is_test),#[path]included.inline-tests(feat(rules): inline-tests moves inline tests over 30% of their file to a file of their own #28) now also counts an inline module behind a test feature, which changes none of its counts.The walk (
rules/walk.rs): onesynvisitor tracks each node's scope (test, constant) and passes function calls, method calls and macros to a rule'sInspect. It also visits macro arguments that parse as expressions, such asprintln!andassert_eq!.No
--fix: naming the constant takes judgement.The other limits the inventory mentions (
with_capacity,take, byte sizes) are left out until a measurement shows they are worth it.Stacked on #28.
Testing
just check-changed feat/rule-inline-testspasses, and re-measuring gives the counts below again.from_secs(30),from_secs(2 * 60)and afrom_millis(5)insideprintln!fail. These pass:const, astaticand aconst fn;#[tokio::test]function and acfg(feature = "test-util")function;#[cfg(test)] mod tests;file, and a file under acfg(any(test, feature = "test-util"))module;Measured with
rules::report, read-only, on detached worktrees of each repository'sorigin/main(since removed):a17710f52Duration::from_calls; 9 in its xtask; tickers, request timeouts, sleeps in retry loopse99cc0e6btest-utilfixtures, now test code07e8ba44dirk_engine's 10 ms frame sleepSampled hits are what the rule targets, such as
tokio::time::timeout(Duration::from_secs(2), self.store.probe())andTicker::new(Duration::from_mins(1)).Checklist
just readme.)Rulevariant; no xtask change.)just check-changedpasses.Note
Written by Claude Opus 5.5 in Claude Code (via T3 Code)