Skip to content

refactor: prefer-option-over-null, internal sites (1 of 6) - #624

Merged
thomasfosterau merged 1 commit into
trunkfrom
option-null-1-internal
Nov 12, 2026
Merged

thomasfosterau merged 1 commit into
trunkfrom
option-null-1-internal

Conversation

@thomasfosterau

@thomasfosterau thomasfosterau commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

Part of #533. This is PR 1 of 6 in the plan (issue comment 6817425804). It covers category A, the non-exported sites of effect/prefer-option-over-null. At those sites absence is now modelled with Option, with an optional parameter x?: T, or with a guard (P.hasProperty).

effect/prefer-option-over-null: 545 → 440 (−105, against trunk dbae674). The rule stays at warn; PR 6 moves it to error.

Declarations. dist/*.d.ts was diffed between vp run build on trunk dbae674 and on this branch:

  • Every public module's declaration is byte-identical. diff -r shows changes only under dist/internal/: conformance/core, errorMeta, filter, linkage, media, members and responseBody.
  • Those changes are not public. They touch @internal declarations that no public .d.ts reaches. Conformance.d.ts uses only Core.{Probe, Finding, Rule, Outcome, Fixture, Payload, Gap, …}, which are unchanged. Negotiation, index and schema use only MEDIA_TYPE from internal/media. The exports map has no ./internal.
  • No changeset, because nothing public changes.

What changed, by module:

  • internal/linkage: identity returns Option<string>.
  • internal/responseBody: bodyText returns Option<string>.
  • internal/media: MediaRange.weight is Option<number>.
  • internal/filter:
    • keySegments and shorthand return Option.
    • The condition operator and result are Option.
    • The members of the Built draft are Option.
  • internal/errorMeta: errorMetaOf, astOf and indexErrorMeta use Option.
  • internal/sparse: the relationships member is read through R.get.
  • internal/conformance:
    • Observation.contentType, Observation.transportError and Discovered.segment are Option.
    • coverageNote returns Option, and a new joinNotes helper joins notes.
    • pass and settle take note: Option<string>.
  • Server modules:
    • ApiError: the makeWire title, detail and source are Option.
    • Assemble: readRelationship and the include walk return Option.
    • Handlers: requested fieldsets, projectionOf, projecting, bothProjections, buildLinks and linkageLinks use Option.
    • Endpoint: the internal helpers take optional parameters, and the getRelationship include is an Option.
    • Document: parsePointer and astTag.
    • Query: the page defaults and the filter: true field codecs.
    • Resource: nullableBaseAst, descriptorOf, strictOptionalInner, scalarKindOf, parseScalar, Definition.annotations and the memoised family relationships.
  • Other modules:
    • Middleware: sourceOf.
    • Client: isRelabellable, errorMessage, nonNegativeInt, refsOf and related.
    • Conformance: selected and execute.
    • Atomic and ServerErrors: the casts become P.hasProperty guards.
  • New helper. internal/members gains someMember, the Option counterpart of definedMember. It replaces conditional object spreads.
  • Nothing new is unsafe. The diff adds no any and no Function.cast.

Hot paths:

  • internal/linkage: linkageOf runs for every element. It uses a new guard, pushIdentity, so it allocates nothing extra. identities no longer allocates an Option for each resource. unlinkedIncluded already allocated one Option per member through fromUndefinedOr, and that count is unchanged.
  • internal/filter:
    • keySegments adds one Some per key. The loop already allocated several arrays per key.
    • A condition's operator and result add one Some each, next to the node they already build.
    • The encodeFilter walk wraps its parent id once per group and shares it among the group's members, so nothing extra is allocated per member.
    • The draft's memberOf and conjunction now keep the Option that MutableHashMap.get already returns. Before, it was unwrapped with getOrUndefined.
  • Handlers projection and the full-linkage walk: the fieldset is wrapped once per transform or build. requestedFor per resource returns the shared None singleton when a type has no set, and allocates one Some next to the MutableHashSet it already built when it has one.
  • Resource.parseScalar: one Some per decoded filter literal, inside an Effect-based decode.

Reclassified: left for later PRs

19 sites were excluded as planned:

  • the Endpoint sentinels: queryConfig ×5, DefaultListQuery ×2, ListPage ×2, ListFilter ×2, GeneratedList ×2, RelPage ×2, GeneratedRelated and GeneratedRelationships
  • the Group sentinels: SurfaceIncluded and flatWire

17 more were classified A but are coupled to published types:

  • Resource.ResolveClearable (1): it is a type-parameter sentinel that attribute's emitted type uses, so it goes to PR 2.
  • Handlers build options (7) and buildLinks options (3): they mirror the | undefined members of the public data / collection options, so they go to PR 3.
  • Resource.declare options (3): they mirror the public attribute options, so they go to PR 3.
  • internal/conformance/report.format's writes, samples and width (3): they mirror the public Conformance.Report and Conformance.format options, so they go to PR 4.

Verification

Run in AGENTS.md order on the rebased branch (93ec8f2 on dbae674):

  • pnpm install --frozen-lockfile: pass
  • vp run build: pass
  • vp check: pass (0 errors)
  • vp run check: pass ("every type gate green")
  • vp run -r test:unit: pass (4010 + 50 + 56 + 73)
  • vp run docgen: pass ("Docs generation succeeded")
  • vp run test:coverage, then fallow audit --base origin/trunk: pass ("No issues in 39 changed files")

Per-rule vp lint deltas against trunk dbae674. No rule grew:

Rule Before After
effect(prefer-option-over-null) 545 440
effect(casting-awareness) 466 455
effect(require-safety-comment-for-type-assertion) 455 441
typescript(no-unsafe-type-assertion) 429 422
Total 2119 1982

Changeset

  • None: the public declarations and runtime behaviour are unchanged.

Notes

The tests that construct or assert internal values were updated with them: internal/media.test.ts (weight) and the conformance core, samples and write tests (Observation, pass).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y5G6PMempKsgjiV1NDcCJY

@changeset-bot

changeset-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 93ec8f2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Model absence with `Option` (or an optional parameter, or a guard) at the
non-exported sites of `effect/prefer-option-over-null`: 546 -> 440. The
public modules' emitted declarations are byte-identical to trunk's; only
`@internal` declarations under `dist/internal/` that no public module
reaches change.

Part of #533.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y5G6PMempKsgjiV1NDcCJY
@thomasfosterau
thomasfosterau merged commit 0ef48e1 into trunk Nov 12, 2026
4 checks passed
@thomasfosterau
thomasfosterau deleted the option-null-1-internal branch November 12, 2026 08:47
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.

2 participants