Skip to content

SimplifyElseBranch puts comment in not the best location #878

Description

@InAnYan

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?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions