JustDummies

Just dummies — but seriously powerful ones.

Documentation sections

JD026: EmptyRelativeUri

PropertyValue
CategoryConstraints (JustDummies.Constraints)
Severity🟡 Warning
Enabled by defaultYes

The chain describes the empty reference, which no URI can be: a relative URI with exactly zero path segments, no query, no fragment and no root renders as the empty string.

Noncompliant

Any.Uri().Relative().WithPathSegments(0)            // JD026: nothing left to render

Compliant

Any.Uri().Relative().WithPathSegments(0).WithQuery()      // "?page=2"
Any.Uri().Relative().WithPathSegments(0).WithFragment()   // "#top"
Any.Uri().Relative().Rooted().WithPathSegments(0)         // "/"
Any.Uri().Relative().WithPathSegments(1)                  // "orders"

Any one of the four is enough: the reference only needs something to render.

Why this one is worth a rule

The library already reports it — but only at Generate(). This is the one member of the constraint family whose failure lands at act time rather than at the arrange line, because emptiness is only settled once the components have been drawn:

AnyGenerationException: A relative URI with exactly 0 path segments and no query,
fragment or root is empty, which is not a valid URI reference. Add a query, a
fragment, Rooted(), or a positive segment count.

The message is clear; the stack is not. It points at the code under test, several frames from the declaration that is wrong — and, when the chain lives in a shared fixture, in a test that never mentions URIs. Moving the report to build time is the whole value of the rule.

What it does not flag

  • A non-relative family. Web(), WebSocket() and Ftp() carry an authority, so a path of zero segments still renders as / and the reference stays valid.
  • A segment count that is not a compile-time constant.

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