Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.openrewrite.java.migrate.lang.StringFormatted leaves hanging spaces/lf #573

Closed
blipper opened this issue Oct 10, 2024 · 10 comments
Closed
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@blipper
Copy link

blipper commented Oct 10, 2024

class A {
    void foo(String bar) {
        String.format(
         "my string %s", bar);
    }
}

What did you expect to see?

class A {
    void foo(String bar) {
         "my string %s".formatted(bar);
    }
}

What did you see instead?

class A {
    void foo(String bar) {

         "my string %s".formatted(bar);
    }
}

This leaves a line feed above. This matters because checkstyle will complain about trailing spaces.

@blipper blipper added the bug Something isn't working label Oct 10, 2024
@bsmahi
Copy link

bsmahi commented Oct 11, 2024

Hi @blipper could you please let me know which recipe you have used for the above. I will try to assist you on resolution.
Thanks,
Mahi

@timtebeek timtebeek changed the title org.openrewrite.java.migrate.lang.StringFormatted leaves hanging spaces/lf org.openrewrite.java.migrate.lang.StringFormatted leaves hanging spaces/lf Oct 11, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Oct 11, 2024
@timtebeek
Copy link
Contributor

Thanks both; looks like we should retain the prefix of the original method invocation, as opposed to the prefix of the first String argument.

@timtebeek timtebeek added the good first issue Good for newcomers label Oct 11, 2024
@coderustic
Copy link

Is anyone working on this? If not I want to contribute

@timtebeek
Copy link
Contributor

Is anyone working on this? If not I want to contribute

Hi! No not yet; feel free to throw up a draft PR with a new unit test and then we can work from there.

@coderustic
Copy link

coderustic commented Oct 11, 2024

@timtebeek I tried to add a test to reproduce the issue as suggested, but I am wondering if this is fixed by #453. As you can see the previous testcase just above the newly added test in the draft MR.

When I remove the .withPrefix(Space.EMPTY) added as part of the fix for #453 then my test fails with a leading linefeed.

@coderustic
Copy link

coderustic commented Oct 11, 2024

@blipper what version you were using?

@timtebeek
Copy link
Contributor

Thanks for the effort to reproduce @coderustic ! We indeed have the version number as part of the bug report template:
https://github.com/openrewrite/.github/blob/46bd203a479256d1afa37e1ac3c4146c4bab201a/.github/ISSUE_TEMPLATE/bug_report.md?plain=1#L15-L31
I'll optimistically close this issue; we can reopen if @blipper was using a newer version; but then ideally we'd see a failing unit test as an example.

@blipper
Copy link
Author

blipper commented Oct 11, 2024

Sorry. I was using 8.34.0

@coderustic
Copy link

What's rewrite-migrate-java version? Looks like 8.34.0 is released 8/28/24 while #556 is merged 9/15/24. So I would ask you to retest with latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Archived in project
Development

No branches or pull requests

4 participants