Skip to content

[prism] Fix comment check for expression-led call chains#786

Merged
reese merged 2 commits intotrunkfrom
reese-expression-chain-comment-handling
Jan 15, 2026
Merged

[prism] Fix comment check for expression-led call chains#786
reese merged 2 commits intotrunkfrom
reese-expression-chain-comment-handling

Conversation

@reese
Copy link
Collaborator

@reese reese commented Jan 15, 2026

I was writing the test cases I promised in #770 but found several edge cases that either formatted incorrectly or were simply not idempotent over multiple formats. This PR adds a bunch of fixtures around this particular scenario (call chains starting with expressions and comments between/around the first caller). Ripper has almost the same behavior, though it has the same idempotency issues that this intends to resolve, so I've made this a Prism-only test case.

The specific change in logic is that previously we were only checking for comments between the end of the leading expression and the dot-operator, like this:

[
  foo
] # a comment goes here!
  .freeze

But really, the check is trying to look for any comment that would actually render in that space. This means that in the comment above, we actually don't care about that comment (because it will always get shifted inside the closing brace), but it also means we do care about comments that would render there, such as trailing comments that might be outside of the call chain proper, such as

[
  foo
]
  .freeze # Don't forget about this one!

@reese reese merged commit 3d2a487 into trunk Jan 15, 2026
8 checks passed
@reese reese deleted the reese-expression-chain-comment-handling branch January 15, 2026 20:25
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