Skip to content

fix: comments must not break rewritten assertions - #1112

Draft
cortlepp wants to merge 1 commit into
openrewrite:mainfrom
cortlepp:fix/assert-to-assertion-comments
Draft

fix: comments must not break rewritten assertions#1112
cortlepp wants to merge 1 commit into
openrewrite:mainfrom
cortlepp:fix/assert-to-assertion-comments

Conversation

@cortlepp

Copy link
Copy Markdown
Contributor

What's changed?

The AssertToAssertions recipe currently does not handle comments correctly when reordering arguments, which can lead to compilation errors after applying the recipe.

What's your motivation?

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

@timtebeek

Have you considered any alternatives or workarounds?

Any additional context

Checklist

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Aug 27, 2026
@cortlepp
cortlepp marked this pull request as draft August 27, 2026 09:20
@cortlepp

Copy link
Copy Markdown
Contributor Author

@timtebeek before trying to come up with a fix I wanted to check with you what a good solution would look like (the one I gave in the test is not necessarily it). I think technically the issue is that the whitespace rewriting seems not to take linebreaks into account, which can break single line comments (like in the test example). We could of course try to fix that, or we could may convert the single line comments to multi-line ones /* */ which would allow us to keep the overall "shape" of the expression intact (which the current implementation does, but without proper comment handling). IMO option two might be easier to get right and it would preserve the original intent of why the expression was written in a that specific way. But I don't have a strong opinion on this, I think the main issue is that comments can currently cause compilation errors and that we should fix that in some way.

@timtebeek

Copy link
Copy Markdown
Member

hi! I'm about to take some time off, so I'll respond briefly, but recommend colleagues for further follow up.

I'd lean towards keeping the comments in place at the end, and turning // into /* */ could run into trouble with // */ still a comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants