Skip to content

feat(rules): add mapMapErrorToMapBoth diagnostic - #732

Open
FNDEVVE wants to merge 1 commit into
Effect-TS:mainfrom
FNDEVVE:feat/mapmaperror-to-mapboth
Open

FNDEVVE wants to merge 1 commit into
Effect-TS:mainfrom
FNDEVVE:feat/mapmaperror-to-mapboth

Conversation

@FNDEVVE

@FNDEVVE FNDEVVE commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Adds the mapMapErrorToMapBoth diagnostic (TS377132, group style, v3+v4) for issue #628.

Transforming both channels with two adjacent combinators — Effect.map + Effect.mapError in either order — is exactly what Effect.mapBoth({ onSuccess, onFailure }) does in one step. The rule matches direct adjacency in pipe/pipeable chains (via checker symbol resolution, mirroring effectMapFlatten) plus the nested data-first shapes map(mapError(eff, g), f) and mapError(map(eff, f), g). Since the channels are independent, the rewrite is always behavior-preserving. Non-adjacent pairs stay silent.

// Before
const isPositive = fetchCount.pipe(
  Effect.map((n) => n > 0),
  Effect.mapError((message) => new TaskError({ message }))
)
// TS377132: `Effect.mapBoth` expresses these failure and success transformations more directly than adjacent `Effect.map` and `Effect.mapError`. effect(mapMapErrorToMapBoth)

// After
const isPositive = fetchCount.pipe(
  Effect.mapBoth({
    onSuccess: (n) => n > 0,
    onFailure: (message) => new TaskError({ message })
  })
)

Closes #628.

Verification

  • go test ./internal/rules: pass (incl. TestRuleDocs/TestMetadataJSON/TestReadmeTable)
  • go test ./internal/effecttest (full package): pass — 5 diagnostics on v4 BAD cases, no collateral on existing fixtures
  • pnpm lint: clean

Flags directly adjacent Effect.map + Effect.mapError pairs (either
order, pipe/pipeable and nested data-first shapes), suggesting a
single Effect.mapBoth.

Closes Effect-TS#628
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.

Rule proposal: adjacent Effect.map + Effect.mapError re-implements Effect.mapBoth

1 participant