Skip to content

refactor: use UnwrapIdentityForwarder in mapSomeToAsSome - #676

Merged
mattiamanzati merged 1 commit into
mainfrom
t3code/find-identity-forwarder-diagnostics
Aug 26, 2026
Merged

refactor: use UnwrapIdentityForwarder in mapSomeToAsSome#676
mattiamanzati merged 1 commit into
mainfrom
t3code/find-identity-forwarder-diagnostics

Conversation

@mattiamanzati

Copy link
Copy Markdown
Contributor

What changed

isOptionSomeMapper in internal/rules/map_some_to_as_some.go was a hand-rolled near-duplicate of the UnwrapIdentityForwarder helper introduced with the catchDieToOrDie diagnostic (#674). This PR replaces the ~44 lines of manual lambda matching with the shared helper, keeping the rule-specific strictness on top.

To support that, TypeParser.UnwrapIdentityForwarder now returns a third value: the forwarder's parameter declaration (nil when no unwrap happened). Callers that need stricter guards than the helper — like this rule — can inspect it without re-parsing the lambda. The existing catchDieToOrDie call site and the helper's unit test were adapted, and the test now asserts the parameter is returned exactly when an unwrap occurs.

Behavioral change

The rule now also recognizes identity-forwarding function expressions, which the previous arrow-only guard excluded:

// previously missed, now triggers with the "Replace with Effect.asSome" quick fix:
export const example = numberEffect.pipe(
  Effect.map(function (value) {
    return Option.some(value)
  })
)
// fix result:
export const example = numberEffect.pipe(
  Effect.asSome
)

Both intentional negative cases are preserved, since they can change the resulting Option type:

  • annotated or optional mapper parameters: Effect.map((value: number) => Option.some(value)) (covered by the shouldNotTriggerAnnotated fixture)
  • explicit type arguments on the inner call: Effect.map((value) => Option.some<number>(value))

Testing

  • New shouldTriggerFunctionExpression fixture case in both effect-v3 and effect-v4, with regenerated diagnostics/quickfix/pipings/flows baselines verifying the diagnostic fires and the quick fix rewrites to Effect.asSome.
  • pnpm setup-repo, pnpm lint, pnpm check, and the full pnpm test suite all pass.

🤖 Generated with Claude Code

Replaces the hand-rolled identity-forwarder matching in isOptionSomeMapper
with the shared typeparser helper. The helper now also returns the
forwarder's parameter declaration so callers can reject annotated or
optional parameters. As a side effect the rule now matches identity-
forwarding function expressions too.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mattiamanzati
mattiamanzati merged commit 2ae20c4 into main Aug 26, 2026
6 checks passed
@mattiamanzati
mattiamanzati deleted the t3code/find-identity-forwarder-diagnostics branch August 26, 2026 11:40
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.

1 participant