Skip to content

feat(rules): inline-limits makes Durations with literals named constants - #30

Draft
PiquelChips wants to merge 1 commit into
feat/rule-inline-testsfrom
feat/rule-inline-limits
Draft

PiquelChips wants to merge 1 commit into
feat/rule-inline-testsfrom
feat/rule-inline-limits

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

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-limits fails on Duration::from_* called with a number, or arithmetic on numbers, outside a const or static item, a const fn and test code. missing_docs already requires the constant's doc comment.

  • const fn counts as constant: piqueld's DockerTimeout::duration and its store's sync timeouts are const fn tables keyed by a documented enum, which already names each limit.

  • Test code, which the next rules reuse:

    • what a test attribute marks (#[test], #[tokio::test], any …::test);
    • what a cfg requiring test or a feature named for tests marks (cfg(any(test, feature = "test-util")), sourceorigin's fixtures);
    • the files such a module declares, plus integration tests and benchmarks: whatever the base's module walk reaches only as test code (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): one syn visitor tracks each node's scope (test, constant) and passes function calls, method calls and macros to a rule's Inspect. It also visits macro arguments that parse as expressions, such as println! and assert_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

  • Rebased onto the amended chain. just check-changed feat/rule-inline-tests passes, and re-measuring gives the counts below again.
  • New fixture test: inline from_secs(30), from_secs(2 * 60) and a from_millis(5) inside println! fail. These pass:
    • a const, a static and a const fn;
    • a non-literal argument;
    • a #[tokio::test] function and a cfg(feature = "test-util") function;
    • a #[cfg(test)] mod tests; file, and a file under a cfg(any(test, feature = "test-util")) module;
    • an integration test.

Measured with rules::report, read-only, on detached worktrees of each repository's origin/main (since removed):

violations notes
piqueld a17710f52 53 of 385 Duration::from_ calls; 9 in its xtask; tickers, request timeouts, sleeps in retry loops
sourceorigin e99cc0e6b 0 its one hit was the test-util fixtures, now test code
DirkEngine 07e8ba44 1 dirk_engine's 10 ms frame sleep

Sampled hits are what the rule targets, such as tokio::time::timeout(Duration::from_secs(2), self.store.probe()) and Ticker::new(Duration::from_mins(1)).

Checklist

  • The crate's README (its documentation on docs.rs) shows the change, and a repository's xtask can still follow it. (just readme.)
  • A change to the public API is noted for the next release, with what each repository's xtask must change. (A new Rule variant; no xtask change.)
  • just check-changed passes.

Note

Written by Claude Opus 5.5 in Claude Code (via T3 Code)

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
PiquelChips force-pushed the feat/rule-inline-limits branch from 4a8fa5d to f1f4399 Compare November 22, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant