Repository navigation
refactor: prefer-option-over-null, internal sites (1 of 6) - #624
Merged
Merged
Conversation
|
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
force-pushed
the
option-null-1-internal
branch
from
November 12, 2026 08:43
504d23d to
93ec8f2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withOption, with an optional parameterx?: T, or with a guard (P.hasProperty).effect/prefer-option-over-null: 545 → 440 (−105, against trunk dbae674). The rule stays atwarn; PR 6 moves it to error.Declarations.
dist/*.d.tswas diffed betweenvp run buildon trunk dbae674 and on this branch:diff -rshows changes only underdist/internal/:conformance/core,errorMeta,filter,linkage,media,membersandresponseBody.@internaldeclarations that no public.d.tsreaches.Conformance.d.tsuses onlyCore.{Probe, Finding, Rule, Outcome, Fixture, Payload, Gap, …}, which are unchanged.Negotiation,indexandschemause onlyMEDIA_TYPEfrominternal/media. The exports map has no./internal.What changed, by module:
internal/linkage:identityreturnsOption<string>.internal/responseBody:bodyTextreturnsOption<string>.internal/media:MediaRange.weightisOption<number>.internal/filter:keySegmentsandshorthandreturnOption.conditionoperator and result areOption.Builtdraft areOption.internal/errorMeta:errorMetaOf,astOfandindexErrorMetauseOption.internal/sparse: the relationships member is read throughR.get.internal/conformance:Observation.contentType,Observation.transportErrorandDiscovered.segmentareOption.coverageNotereturnsOption, and a newjoinNoteshelper joins notes.passandsettletakenote: Option<string>.ApiError: themakeWiretitle,detailandsourceareOption.Assemble:readRelationshipand the include walk returnOption.Handlers: requested fieldsets,projectionOf,projecting,bothProjections,buildLinksandlinkageLinksuseOption.Endpoint: the internal helpers take optional parameters, and thegetRelationshipinclude is anOption.Document:parsePointerandastTag.Query: the page defaults and thefilter: truefield codecs.Resource:nullableBaseAst,descriptorOf,strictOptionalInner,scalarKindOf,parseScalar,Definition.annotationsand the memoised family relationships.Middleware:sourceOf.Client:isRelabellable,errorMessage,nonNegativeInt,refsOfandrelated.Conformance:selectedandexecute.AtomicandServerErrors: the casts becomeP.hasPropertyguards.internal/membersgainssomeMember, theOptioncounterpart ofdefinedMember. It replaces conditional object spreads.anyand noFunction.cast.Hot paths:
internal/linkage:linkageOfruns for every element. It uses a new guard,pushIdentity, so it allocates nothing extra.identitiesno longer allocates anOptionfor each resource.unlinkedIncludedalready allocated oneOptionper member throughfromUndefinedOr, and that count is unchanged.internal/filter:keySegmentsadds oneSomeper key. The loop already allocated several arrays per key.Someeach, next to the node they already build.encodeFilterwalk wraps its parent id once per group and shares it among the group's members, so nothing extra is allocated per member.memberOfandconjunctionnow keep theOptionthatMutableHashMap.getalready returns. Before, it was unwrapped withgetOrUndefined.Handlersprojection and the full-linkage walk: the fieldset is wrapped once per transform or build.requestedForper resource returns the sharedNonesingleton when a type has no set, and allocates oneSomenext to theMutableHashSetit already built when it has one.Resource.parseScalar: oneSomeper decoded filter literal, inside an Effect-based decode.Reclassified: left for later PRs
19 sites were excluded as planned:
Endpointsentinels:queryConfig×5,DefaultListQuery×2,ListPage×2,ListFilter×2,GeneratedList×2,RelPage×2,GeneratedRelatedandGeneratedRelationshipsGroupsentinels:SurfaceIncludedandflatWire17 more were classified A but are coupled to published types:
Resource.ResolveClearable(1): it is a type-parameter sentinel thatattribute's emitted type uses, so it goes to PR 2.Handlersbuildoptions (7) andbuildLinksoptions (3): they mirror the| undefinedmembers of the publicdata/collectionoptions, so they go to PR 3.Resource.declareoptions (3): they mirror the publicattributeoptions, so they go to PR 3.internal/conformance/report.format'swrites,samplesandwidth(3): they mirror the publicConformance.ReportandConformance.formatoptions, so they go to PR 4.Verification
Run in AGENTS.md order on the rebased branch (93ec8f2 on dbae674):
pnpm install --frozen-lockfile: passvp run build: passvp 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, thenfallow audit --base origin/trunk: pass ("No issues in 39 changed files")Per-rule
vp lintdeltas against trunk dbae674. No rule grew:effect(prefer-option-over-null)effect(casting-awareness)effect(require-safety-comment-for-type-assertion)typescript(no-unsafe-type-assertion)Changeset
Notes
The tests that construct or assert internal values were updated with them:
internal/media.test.ts(weight) and the conformancecore,samplesandwritetests (Observation,pass).🤖 Generated with Claude Code
https://claude.ai/code/session_01Y5G6PMempKsgjiV1NDcCJY