JustDummies

Just dummies — but seriously powerful ones.

Documentation sections

JD006: DiscardedGeneratorResult

PropertyValue
CategoryUsage (JustDummies.Usage)
Severity🟠 Warning
Enabled by defaultYes

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: inside Any.Reproducibly(() => { ... }) a dropped constraint is one statement of a block, not the body itself, and stays reported.
  • A discarded generated valueGenerate() returns the value, which is a different and much weaker smell.

Read the source, or correct it there opens in a new tab· Mirrored from lib-v1.0.0-preview.6