openrewrite / openrewrite/rewrite-static-analysis
`SimplifyElseBranch` puts comment in not the best location
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 62
- Forks
- 112
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 40
Description
What version of OpenRewrite are you using?
I am using
- Maven/Gradle plugin v7.32.1
- rewrite-recipe-bom:3.30.0
How are you running OpenRewrite?
I am using the Gradle plugin.
What is the smallest, simplest way to reproduce the problem?
- The real-world example: https://github.com/JabRef/jabref/pull/15665/changes/#diff-db2f9211ebcdff5b3e3a68cbb6c1f69202b33d85cfae155215326fc4ddad5701R140.
Sorry for not providing an MWE, because of the lack of time.
I guess a simpler version is:
Before:
if (<condition>) {
do1();
} else {
// Comment.
if (<condition 2>) {
do2();
}
}
What did you expect to see?
Not sure if this is a better version.
if (<condition>) {
do1();
} else if (<condition 2>) {
// Comment.
do2();
}
What did you see instead?
if (<condition>) {
do1();
} else // Comment.
if (<condition 2>) {
do2();
}
Which is technically right, but a bit crazy. I have never seen such a placement of a comment.
It's not really a bug, but a discussion on the style and approach.
What is the full stack trace of any errors you encountered?
No errors.
Are you interested in contributing a fix to OpenRewrite?
Yes, but I don't have time right now. Maybe later
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the SimplifyElseBranch recipe entry point and reproduce the issue with the Java examples in the report. Compare the current output, which places the comment after else, with the proposed output; done means the comment is retained in the more conventional location without changing the conditional structure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100