Repository navigation
refactor!: prefer-option-over-null to zero, at error (6 of 6) - #631
Merged
Merged
Conversation
The last 154 sites, all in tests, type tests and examples, plus the three
inline disables trunk carried for the rule:
- examples: `findFailure` helpers give way to `Cause.findErrorOption`;
`resolveIncluded` / `sortBy` / `paginate` take optional parameters; the
search `matches` reads `Option`s; `patchAttributes` takes the decoded
`Schema.optional` struct; the atomic `ResultEntry` is `Atomic.Result`'s Type.
- optional-attribute type assertions pin the member with
`Pick<…, "k">` against `{ readonly k?: T }`, or the decoded type with
`Schema.optional<S>["Type"]` / `Schema.NullOr<S>["Type"]`.
- `assertType<T | undefined>(x)` becomes
`assertType<Option.Option<T>>(Option.fromUndefinedOr(x))`.
- test helpers returning a maybe value return `Option`
(`resolveRelative`, Filter/Sort `annotationOf`, the sort profile's NULL).
- `Negotiation.Options`' `onExplicitRefusal` / `extensions` drop
`| undefined` (Breaking changeset).
`effect/prefer-option-over-null` now runs at the preset's `error`, and the
AGENTS.md `exactOptionalPropertyTypes` bullet states the family rule.
Part of #533.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y5G6PMempKsgjiV1NDcCJY
🦋 Changeset detectedLatest commit: 813c1ef The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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 (6 of 6, the last). This PR clears the remaining
effect/prefer-option-over-nullsites and removes the rule'swarnline, so the preset now runs it aterror.Site count: 154 → 0. Trunk 3c74fe9 also had three inline
oxlint-disable-next-line effect/prefer-option-over-nullcomments: two insrc/Negotiation.tsand one insrc/Resource.undeclared.test.ts. They are gone too. No disable or override for the rule is left anywhere in the repo.Category D: tests, type tests and examples.
findFailure(): E | undefinedis replaced byCause.findErrorOption. Call sites now useassert(Option.isSome(error) && error.value instanceof X)orassert(Option.exists(…, (e) => e instanceof X)), which also removes the(error as X)casts. The same applies tosrc/Endpoint.test.ts.resolveIncluded/resolve*Included,sortBy,paginateandarticleCommentPagenow take optional parameters.matchesreadsReadonlyArray<Option<string>>.patchAttributes(also the one inEndpoint.test.ts) takesSchema.Struct<{ [K in keyof A]: Schema.optional<Schema.Schema<A[K]>> }>["Type"], which is the decoded update attributes, spelled from the schema.ResultEntryisAtomic.Result<…>["Type"].expectTypeOf(x.k).toEqualTypeOf<T | undefined>()becameexpectTypeOf<Pick<typeof x, "k">>().toEqualTypeOf<{ readonly k?: T }>(). Where the member really is?: T | undefined(aSchema.optionalfield), it is checked againstSchema.optional<S>["Type"]instead.T | nullis checked againstSchema.NullOr<S>["Type"].| undefined, losesreadonlyor changes type.assertType<T | undefined>(x)becameassertType<Option.Option<T>>(Option.fromUndefinedOr(x)). It is the same assignability check.Option:test/entry-points.test.ts'sresolveRelativenow usesArr.findFirst.annotationOflookups.include-surface'svalidate.Conformance.sort.test.ts, where NULL is nowOption.none().User | null | undefined) are now optional parameters (viewer?: User).Conformance.test.ts(Attributes,Identifier, the to-one linkage) are derived from schemas.The flip:
vite.config.ts: the"effect/prefer-option-over-null": "warn"line is deleted. The count comment now lists the rule among those that reached zero and are aterror.The convention:
AGENTS.md'sexactOptionalPropertyTypesbullet (which prescribed?: T | undefined) is rewritten to state the family rule:readonly x?: T, and optional parameters arex?: T;x?: Option.Option<T>;Option;null, spelled from their schemas;definedMember/someMemberbecause conditional empty-object spread is banned..claude/CLAUDE.mdimports AGENTS.md and does not repeat the bullet. CONTRIBUTING.md, README.md and docs/ give no| undefinedadvice. The README lines that mention| undefineddescribe decoded wire types and are still accurate.Lint deltas (
vp lint, per rule)effect/prefer-option-over-nulleffect/casting-awarenesseffect/require-safety-comment-for-type-assertiontypescript/no-unsafe-type-assertionNo rule grew. In total: 0 errors and 1506 warnings, down from 1692 warnings.
Verification
pnpm install --frozen-lockfile— passvp run build— passvp check— pass ("Found 0 errors and 1506 warnings in 184 files")vp run check(sources, type-level tests, examples, emitted declarations) — pass (8/8 successful)vp run -r test:unit— pass (4010 + 56 + 73 + 50 tests)vp run docgen(every JSDoc@examplecompiled and executed) — pass. I also ran it with--no-cache.vp run test:coverage, thenfallow audit --base origin/trunk— verdictwarn(notfail). The 6 complexity findings are on existing example and test functions; dead code is 0.Changeset
.changeset/option-over-null-negotiation-rest.md— minor, Breaking.Negotiation.Options'onExplicitRefusalandextensionswere the last two published?: T | undefinedmembers; trunk had kept them behind inline disables. They are nowreadonly x?: T, like the rest ofNegotiation.Options. The changeset includes a migration note: omit the key, or spreaddefinedMember(…). It lands before the next release, alongside the other pending breaks in this series.Everything else is test, example and docs only.
Notes
src/Assemble.tsstill has two JSDoc examples spelled(viewer: User | null | undefined) => …. The rule does not read comments, they still compile and run under docgen, and I left them as they are.client-hydration.types.tsused to assertdoc.data.links?.self as string | undefined, which is a cast, not a check. It now pins the link totypeof Document.Link.Encoded: the wire link union, strings rather thanURLs.Generated by Claude Code