Skip to content

refactor!: prefer-option-over-null to zero, at error (6 of 6) - #631

Merged
thomasfosterau merged 1 commit into
trunkfrom
option-null-6-tests-flip
Nov 12, 2026
Merged

thomasfosterau merged 1 commit into
trunkfrom
option-null-6-tests-flip

Conversation

@thomasfosterau

Copy link
Copy Markdown
Owner

Summary

Part of #533 (6 of 6, the last). This PR clears the remaining effect/prefer-option-over-null sites and removes the rule's warn line, so the preset now runs it at error.

Site count: 154 → 0. Trunk 3c74fe9 also had three inline oxlint-disable-next-line effect/prefer-option-over-null comments: two in src/Negotiation.ts and one in src/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.

  • Examples' findFailure(): E | undefined is replaced by Cause.findErrorOption. Call sites now use assert(Option.isSome(error) && error.value instanceof X) or assert(Option.exists(…, (e) => e instanceof X)), which also removes the (error as X) casts. The same applies to src/Endpoint.test.ts.
  • Examples' helpers:
    • resolveIncluded / resolve*Included, sortBy, paginate and articleCommentPage now take optional parameters.
    • The search matches reads ReadonlyArray<Option<string>>.
    • patchAttributes (also the one in Endpoint.test.ts) takes Schema.Struct<{ [K in keyof A]: Schema.optional<Schema.Schema<A[K]>> }>["Type"], which is the decoded update attributes, spelled from the schema.
    • The blog's atomic ResultEntry is Atomic.Result<…>["Type"].
  • Optional-member type assertions:
    • expectTypeOf(x.k).toEqualTypeOf<T | undefined>() became expectTypeOf<Pick<typeof x, "k">>().toEqualTypeOf<{ readonly k?: T }>(). Where the member really is ?: T | undefined (a Schema.optional field), it is checked against Schema.optional<S>["Type"] instead.
    • T | null is checked against Schema.NullOr<S>["Type"].
    • I checked by hand that each form still fails when the member turns required, gains | undefined, loses readonly or changes type.
  • assertType<T | undefined>(x) became assertType<Option.Option<T>>(Option.fromUndefinedOr(x)). It is the same assignability check.
  • Test helpers that return a maybe value now return Option:
    • test/entry-points.test.ts's resolveRelative now uses Arr.findFirst.
    • The Filter/Sort annotationOf lookups.
    • include-surface's validate.
    • The sort profile in Conformance.sort.test.ts, where NULL is now Option.none().
  • Viewer-shaped parameters (User | null | undefined) are now optional parameters (viewer?: User).
  • Wire records in 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 at error.

The convention:

  • AGENTS.md's exactOptionalPropertyTypes bullet (which prescribed ?: T | undefined) is rewritten to state the family rule:
    • options members are readonly x?: T, and optional parameters are x?: T;
    • Option-valued optional properties are x?: Option.Option<T>;
    • "maybe" results are Option;
    • wire shapes keep native optionals and null, spelled from their schemas;
    • internal forwarding uses definedMember / someMember because conditional empty-object spread is banned.
  • .claude/CLAUDE.md imports AGENTS.md and does not repeat the bullet. CONTRIBUTING.md, README.md and docs/ give no | undefined advice. The README lines that mention | undefined describe decoded wire types and are still accurate.

Lint deltas (vp lint, per rule)

rule before after
effect/prefer-option-over-null 154 0
effect/casting-awareness 454 444
effect/require-safety-comment-for-type-assertion 440 428
typescript/no-unsafe-type-assertion 420 410
every other rule — unchanged

No rule grew. In total: 0 errors and 1506 warnings, down from 1692 warnings.

Verification

  • pnpm install --frozen-lockfile — pass
  • vp run build — pass
  • vp 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 @example compiled and executed) — pass. I also ran it with --no-cache.
  • vp run test:coverage, then fallow audit --base origin/trunk — verdict warn (not fail). 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' onExplicitRefusal and extensions were the last two published ?: T | undefined members; trunk had kept them behind inline disables. They are now readonly x?: T, like the rest of Negotiation.Options. The changeset includes a migration note: omit the key, or spread definedMember(…). 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.ts still 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.ts used to assert doc.data.links?.self as string | undefined, which is a cast, not a check. It now pins the link to typeof Document.Link.Encoded: the wire link union, strings rather than URLs.

Generated by Claude Code

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-bot

changeset-bot Bot commented Nov 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 813c1ef

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@thomasfosterau/effect-jsonapi Minor

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

@thomasfosterau thomasfosterau changed the title refactor: prefer-option-over-null to zero, at error (6 of 6) refactor!: prefer-option-over-null to zero, at error (6 of 6) Nov 12, 2026
@thomasfosterau
thomasfosterau merged commit 442a256 into trunk Nov 12, 2026
5 checks passed
@thomasfosterau
thomasfosterau deleted the option-null-6-tests-flip branch November 12, 2026 10:18
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