From f0cd0827da9686882d153d24c75bba11789754ba Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 7 Nov 2026 07:38:58 +0000 Subject: [PATCH] chore(lint): clear six small @effect/tsgo rules (#536) `prefer-succeed-some-or-none`, `effect-succeed-with-void` (as `Effect.undefined`, which keeps the `undefined` success type), `unnecessary-fail-yieldable-error`, `unnecessary-pipe-chain`, `flat-map-conditional-to-filter-or-fail` and `schema-sync-in-effect` now report no site. No behaviour changes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Y5G6PMx5cf5KQSi9sQ4tu1 --- examples/github/handlers.ts | 7 +- examples/github/test/github.test.ts | 5 +- examples/northwind/handlers.ts | 2 +- examples/northwind/test/northwind.test.ts | 5 +- src/ApiError.ts | 109 +++++++++++----------- src/Assemble.ts | 2 +- src/Client.ts | 4 +- src/Handlers.ts | 2 +- src/Idempotency.ts | 6 +- src/Middleware.ts | 2 +- src/ResourceHandlers.ts | 2 +- src/internal/conformance/core.ts | 2 +- src/internal/conformance/crawl.ts | 4 +- src/internal/conformance/evaluation.ts | 13 ++- src/internal/wireNames.test.ts | 9 +- 15 files changed, 83 insertions(+), 91 deletions(-) diff --git a/examples/github/handlers.ts b/examples/github/handlers.ts index 3a377ff7..22f24e1b 100644 --- a/examples/github/handlers.ts +++ b/examples/github/handlers.ts @@ -334,10 +334,9 @@ const loadIssue = (id: string): Effect.Effect => { const loadUnlockedIssue = (id: string): Effect.Effect => loadIssue(id).pipe( - Effect.flatMap((issue) => - issue.attributes.locked - ? Effect.fail(new IssueLocked({ id: issue.id })) - : Effect.succeed(issue), + Effect.filterOrFail( + (issue) => !issue.attributes.locked, + (issue) => new IssueLocked({ id: issue.id }), ), ); diff --git a/examples/github/test/github.test.ts b/examples/github/test/github.test.ts index 84b81be6..459f6da2 100644 --- a/examples/github/test/github.test.ts +++ b/examples/github/test/github.test.ts @@ -358,9 +358,8 @@ describe("github example: pagination links carry the request's query (#447)", () }); const next = first.links?.next; assert(Predicate.isString(next)); - const second = yield* client.issues.list({ - query: Schema.decodeUnknownSync(IssuesQuery)(searchOf(next)), - }); + const query = yield* Schema.decodeUnknownEffect(IssuesQuery)(searchOf(next)); + const second = yield* client.issues.list({ query }); return [first, second] as const; }), ); diff --git a/examples/northwind/handlers.ts b/examples/northwind/handlers.ts index f2f86398..d8c6cbb5 100644 --- a/examples/northwind/handlers.ts +++ b/examples/northwind/handlers.ts @@ -779,7 +779,7 @@ export const ProductsLive = HttpApiBuilder.group(Api, "products", (handlers) => Effect.gen(function* () { const name = payload.data.attributes.name; if (Iterable.some(store.products.values(), (existing) => existing.attributes.name === name)) - return yield* Effect.fail(new ProductNameTaken({ name })); + return yield* new ProductNameTaken({ name }); // `category` and `supplier` are required (`one`) relationships — the // payload always carries them, and both targets must exist. yield* loadCategory(payload.data.relationships.category.data.id); diff --git a/examples/northwind/test/northwind.test.ts b/examples/northwind/test/northwind.test.ts index baa90992..0dc3167f 100644 --- a/examples/northwind/test/northwind.test.ts +++ b/examples/northwind/test/northwind.test.ts @@ -382,9 +382,8 @@ describe("northwind example: pagination links carry the request's query (#447)", }); const next = first.links?.next; assert(Predicate.isString(next)); - const second = yield* client.products.list({ - query: Schema.decodeUnknownSync(ProductsQuery)(searchOf(next)), - }); + const query = yield* Schema.decodeUnknownEffect(ProductsQuery)(searchOf(next)); + const second = yield* client.products.list({ query }); return [first, second] as const; }), ); diff --git a/src/ApiError.ts b/src/ApiError.ts index 456f3550..eb9a8966 100644 --- a/src/ApiError.ts +++ b/src/ApiError.ts @@ -232,61 +232,60 @@ const makeWire = ( }), ) as unknown as typeof WireDocument; - const wire = strictDocument - .pipe( - Schema.decodeTo( - klass as unknown as Schema.Top, - SchemaTransformation.transform({ - // document -> class encoded form ({ _tag, ...fields }). A field the - // document's `meta` does not carry is left absent (not `undefined`), - // so an optional field decodes from a document another server wrote - // without `meta`; a `detail` field falls back to the error object's - // own `detail` — the source-bearing 400s of the schema-error - // middleware carry it there and nowhere else. - decode: (doc) => { - const first = doc.errors[0]; - const meta = first?.meta ?? {}; - const fields: Record = {}; - for (const key of options.fieldKeys) { - if (key in meta) fields[key] = meta[key]; - else if (key === "detail" && first?.detail !== undefined) fields[key] = first.detail; - } - return { _tag: options.tag, ...fields }; - }, - // class encoded form -> document. An optional field the instance - // leaves absent stays out of `meta` (an `undefined` member is not - // JSON), mirroring `decode` above. - encode: (encoded) => { - const fields = encoded as Record; - const detail = options.detail?.(fields); - const source = options.source?.(fields); - return { - errors: [ - { - status: String(options.status), - code: options.code, - ...definedMember("title", options.title), - ...definedMember("detail", detail), - ...definedMember("source", source), - ...definedMember( - "meta", - Arr.isReadonlyArrayNonEmpty(options.fieldKeys) - ? Object.fromEntries( - options.fieldKeys.flatMap((key) => - fields[key] === undefined ? [] : [[key, fields[key]]], - ), - ) - : undefined, - ), - }, - ], - }; - }, - }), - ), - HttpApiSchema.status(options.status), - ) - .pipe((schema) => asJsonApi(schema)); + const wire = strictDocument.pipe( + Schema.decodeTo( + klass as unknown as Schema.Top, + SchemaTransformation.transform({ + // document -> class encoded form ({ _tag, ...fields }). A field the + // document's `meta` does not carry is left absent (not `undefined`), + // so an optional field decodes from a document another server wrote + // without `meta`; a `detail` field falls back to the error object's + // own `detail` — the source-bearing 400s of the schema-error + // middleware carry it there and nowhere else. + decode: (doc) => { + const first = doc.errors[0]; + const meta = first?.meta ?? {}; + const fields: Record = {}; + for (const key of options.fieldKeys) { + if (key in meta) fields[key] = meta[key]; + else if (key === "detail" && first?.detail !== undefined) fields[key] = first.detail; + } + return { _tag: options.tag, ...fields }; + }, + // class encoded form -> document. An optional field the instance + // leaves absent stays out of `meta` (an `undefined` member is not + // JSON), mirroring `decode` above. + encode: (encoded) => { + const fields = encoded as Record; + const detail = options.detail?.(fields); + const source = options.source?.(fields); + return { + errors: [ + { + status: String(options.status), + code: options.code, + ...definedMember("title", options.title), + ...definedMember("detail", detail), + ...definedMember("source", source), + ...definedMember( + "meta", + Arr.isReadonlyArrayNonEmpty(options.fieldKeys) + ? Object.fromEntries( + options.fieldKeys.flatMap((key) => + fields[key] === undefined ? [] : [[key, fields[key]]], + ), + ) + : undefined, + ), + }, + ], + }; + }, + }), + ), + HttpApiSchema.status(options.status), + (schema) => asJsonApi(schema), + ); wireCache.set(klass, wire); return wire; diff --git a/src/Assemble.ts b/src/Assemble.ts index 5429c2dd..4c3e53db 100644 --- a/src/Assemble.ts +++ b/src/Assemble.ts @@ -748,7 +748,7 @@ const walk = ( Handlers.IncludeTargetServices > => { const include = options.include; - if (include === undefined) return Effect.succeed(undefined); + if (include === undefined) return Effect.undefined; const depth = options.depth ?? MAX_INCLUDE_DEPTH; return Query.validateIncludePaths(include, { includable: options.includable ?? [], diff --git a/src/Client.ts b/src/Client.ts index a9f81139..fca9488e 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -656,7 +656,7 @@ export const decodeErrorDocument = ( */ export const errorDocument = (cause: unknown): Effect.Effect> => { const response = HttpClientError.isHttpClientError(cause) ? cause.response : undefined; - if (response === undefined) return Effect.succeed(Option.none()); + if (response === undefined) return Effect.succeedNone; return response.text.pipe( // The body may be unreadable (already consumed, a broken stream): that is // still "no document", never a second failure on top of the first. @@ -760,7 +760,7 @@ export const isErrorResponse = (u: unknown): u is ErrorResponse => u instanceof */ export const toErrorResponse = (cause: unknown): Effect.Effect> => { if (!HttpClientError.isHttpClientError(cause) || cause.response === undefined) { - return Effect.succeed(Option.none()); + return Effect.succeedNone; } const status = cause.response.status; return errorDocument(cause).pipe( diff --git a/src/Handlers.ts b/src/Handlers.ts index 715a56a9..a92b90bb 100644 --- a/src/Handlers.ts +++ b/src/Handlers.ts @@ -1317,7 +1317,7 @@ export const resolveIncluded = ( IncludeTargetServices > => (paths === undefined - ? Effect.succeed(undefined) + ? Effect.undefined : Arr.isReadonlyArrayEmpty(paths) ? Effect.succeed([]) : resolve( diff --git a/src/Idempotency.ts b/src/Idempotency.ts index 922e4752..c2e58f8d 100644 --- a/src/Idempotency.ts +++ b/src/Idempotency.ts @@ -871,12 +871,10 @@ export const layer = (store: Store): Layer.Layer => // A key already seen: a different request under it is a mismatch; // the same one is still in flight, or replays its recorded response. if (Predicate.isTagged(claim, "InProgress")) { - return yield* Effect.fail( - claim.fingerprint !== print ? new KeyMismatch() : new KeyInProgress(), - ); + return yield* claim.fingerprint !== print ? new KeyMismatch() : new KeyInProgress(); } if (Predicate.isTagged(claim, "Completed")) { - if (claim.fingerprint !== print) return yield* Effect.fail(new KeyMismatch()); + if (claim.fingerprint !== print) return yield* new KeyMismatch(); return replay(claim.response); } diff --git a/src/Middleware.ts b/src/Middleware.ts index e484cf6a..6f8a0fad 100644 --- a/src/Middleware.ts +++ b/src/Middleware.ts @@ -1133,7 +1133,7 @@ export const contentNegotiationLayer = ( ), Effect.withSpan(Span.negotiate), ); - if (error !== undefined) return yield* Effect.fail(error); + if (error !== undefined) return yield* error; return yield* httpEffect; }), ), diff --git a/src/ResourceHandlers.ts b/src/ResourceHandlers.ts index 7c8307dd..b68362a4 100644 --- a/src/ResourceHandlers.ts +++ b/src/ResourceHandlers.ts @@ -461,7 +461,7 @@ export const assertIdMatchesPath = ( const identityTransact: Transact = (effect) => effect; -const none = Effect.succeed(undefined); +const none = Effect.undefined; /** * Builds the `list` / `get` handlers for a read-only resource, keyed by the diff --git a/src/internal/conformance/core.ts b/src/internal/conformance/core.ts index 89d4697d..c4d79fc3 100644 --- a/src/internal/conformance/core.ts +++ b/src/internal/conformance/core.ts @@ -1086,7 +1086,7 @@ export const DEFAULT_REQUEST_TIMEOUT: Duration.Duration = Duration.seconds(30); export const requestTimeoutOf = ( given: Option.Option, ): Effect.Effect> => { - if (Option.isNone(given)) return Effect.succeed(Option.some(DEFAULT_REQUEST_TIMEOUT)); + if (Option.isNone(given)) return Effect.succeedSome(DEFAULT_REQUEST_TIMEOUT); const input = given.value; const timeout = Duration.fromInput(input); if (Option.isSome(timeout) && Duration.isPositive(timeout.value)) { diff --git a/src/internal/conformance/crawl.ts b/src/internal/conformance/crawl.ts index c5577438..701af4e7 100644 --- a/src/internal/conformance/crawl.ts +++ b/src/internal/conformance/crawl.ts @@ -257,7 +257,7 @@ export const budgeted = (ctx: Context, budget: number): Io => { const answers = MutableHashMap.empty(); const refetch = (target: Target): Effect.Effect> => Effect.suspend(() => { - if (spent >= budget) return Effect.succeed(Option.none()); + if (spent >= budget) return Effect.succeedNone; return ctx .request({ url: target.url, headers: jsonApiAccept, requests: budget - spent }) .pipe( @@ -278,7 +278,7 @@ export const budgeted = (ctx: Context, budget: number): Io => { Effect.suspend(() => Option.match(MutableHashMap.get(answers, target.href), { onNone: () => refetch(target), - onSome: (observation) => Effect.succeed(Option.some(observation)), + onSome: (observation) => Effect.succeedSome(observation), }), ), spent: () => spent, diff --git a/src/internal/conformance/evaluation.ts b/src/internal/conformance/evaluation.ts index 29db3dd7..b8e0d08c 100644 --- a/src/internal/conformance/evaluation.ts +++ b/src/internal/conformance/evaluation.ts @@ -989,15 +989,14 @@ const judgeFields = ( Arr.matchLeft(fields, { onEmpty: () => Effect.succeed>([]), onNonEmpty: (field, rest) => - Effect.flatMap( + Effect.filterOrElse( judgeAll(io, ctx, path, candidates, probesOf(field)), + (judged) => Arr.some(judged, Judged.$is("Decided")), (judged): Effect.Effect> => - Arr.some(judged, Judged.$is("Decided")) - ? Effect.succeed(judged) - : Effect.map(judgeFields(io, ctx, path, candidates, rest, probesOf), (after) => [ - ...judged, - ...after, - ]), + Effect.map(judgeFields(io, ctx, path, candidates, rest, probesOf), (after) => [ + ...judged, + ...after, + ]), ), }); diff --git a/src/internal/wireNames.test.ts b/src/internal/wireNames.test.ts index 1be30da7..aa2cccbf 100644 --- a/src/internal/wireNames.test.ts +++ b/src/internal/wireNames.test.ts @@ -227,11 +227,10 @@ describe("wireProperties", () => { // The wire is `x`: read as a plain struct, `a` would be paired with `a`. [ "a transformation from a struct with an encoding of its own", - Schema.Struct({ a: Schema.String }) - .pipe(Schema.encodeKeys({ a: "x" })) - .pipe( - Schema.decodeTo(Schema.Struct({ a: Schema.String }), SchemaTransformation.passthrough()), - ), + Schema.Struct({ a: Schema.String }).pipe( + Schema.encodeKeys({ a: "x" }), + Schema.decodeTo(Schema.Struct({ a: Schema.String }), SchemaTransformation.passthrough()), + ), ], [ "a transformation from a value that is no struct",