refactor: use UnwrapIdentityForwarder in mapSomeToAsSome - #676
Merged
Conversation
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>
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.
What changed
isOptionSomeMapperininternal/rules/map_some_to_as_some.gowas a hand-rolled near-duplicate of theUnwrapIdentityForwarderhelper introduced with thecatchDieToOrDiediagnostic (#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.UnwrapIdentityForwardernow returns a third value: the forwarder's parameter declaration (nilwhen no unwrap happened). Callers that need stricter guards than the helper — like this rule — can inspect it without re-parsing the lambda. The existingcatchDieToOrDiecall 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:
Both intentional negative cases are preserved, since they can change the resulting
Optiontype:Effect.map((value: number) => Option.some(value))(covered by theshouldNotTriggerAnnotatedfixture)Effect.map((value) => Option.some<number>(value))Testing
shouldTriggerFunctionExpressionfixture case in botheffect-v3andeffect-v4, with regenerated diagnostics/quickfix/pipings/flows baselines verifying the diagnostic fires and the quick fix rewrites toEffect.asSome.pnpm setup-repo,pnpm lint,pnpm check, and the fullpnpm testsuite all pass.🤖 Generated with Claude Code