| Property | Value |
|---|---|
| Category | Usage (JustDummies.Usage) |
| Severity | 🟠 Warning |
| Enabled by default | Yes |
A generator is an immutable recipe: every constraint returns a new generator rather than mutating the receiver. So numbers.NonEmpty(); reads like it constrains numbers and constrains nothing at all — the declared invariant is silently dropped.
What makes this worth a build-time diagnostic is the failure shape. The generator keeps drawing from the wider domain, so the test passes on most runs and fails on the one that draws outside it. An unconstrained Any.String() yields the empty string on roughly one run in sixteen: the test is green until it is not, and the value that broke it is gone.
Assign the result back.
Noncompliant
AnyList<int> numbers = Any.ListOf(Any.Int32());
numbers.NonEmpty(); // JD006: the constrained generator is dropped
List<int> values = numbers.Generate(); // may still be empty
Compliant
AnyList<int> numbers = Any.ListOf(Any.Int32()).NonEmpty();
List<int> values = numbers.Generate();
What it does not flag
- An explicit discard —
_ = Any.StringMatching(pattern);. The rule exists because the mistake is silent: a bare call reads as if it mutated the receiver. A discard cannot be misread that way, and it is how a test that only wants the construction to throw spells its intent. (JD002 and JD004 do report_ =, because discarding is never right there.) - A test asserting that a constraint throws, when the illegal call is the whole body of a lambda argument —
Check.ThatCode(() => Any.String().WithLength(3).StartingWith("ORD-")). The exclusion is deliberately narrow: insideAny.Reproducibly(() => { ... })a dropped constraint is one statement of a block, not the body itself, and stays reported. - A discarded generated value —
Generate()returns the value, which is a different and much weaker smell.