Closed Philzen closed 9 months ago
hi @Philzen ; thanks for reporting your findings here! Sorry to hear you're not getting the changes you had hoped for. Both appear related to our style detection and application. High over I can say we do our best to detect the most common style across a project (not just an individual file) and apply what we find to any code changes. It might then help to ensure your project uses a consistent style when it comes to indentation and where to place annotations on methods, if you haven't already.
In this case when we remove a modifier, we also apply our auto formatter on the remainder as seen here for classes https://github.com/openrewrite/rewrite-testing-frameworks/blob/8e1dffba4890771730f37c5ccfbaa0764f4c4754/src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublic.java#L126 And here for methods.
If the automatically detected style does not work for you, you can also pass in an explict style to ensure that any code changes produced as part of a recipe run use a particular format. Hope that helps!
Would you have any further questions that you want to keep this issue open for?
Hi @timtebeek, thanks for your response! And BTW thanks to you and everybody for all your work on those OpenRecipes, they are a priceless support for those kinds of migrations.
For me, this issue is not really a showstopper as i carefully review the diffs after the recipe's have run, so it's just a little (sometimes more, depending on the project size) manual work involved to fix the diffs, but still i'm grateful about OpenRecipe identifying the points of action for me in the first place. I merely wanted to report back to the team that this recipe may not be working expected. So i'll leave it up to you to decide whether to close it.
Without understanding the internals of the format detection, maybe i can provide some context on the project(s) this happens on:
.editorconfig
that defines there should be 4 spaces per indentSo maybe this information could provide guidance for improving the format detection in those methods you referenced.
Would you have any further questions [...]?
Basically, having this mixed formats in the code-base continues to be a nuisance b/c typically one finds out about it in the middle of coding when we have already touched the files, so i was wondering if there is an automated tool to fix this once and for all. And of course, OpenRewrite in all its awesomeness seems to have us covered:
But from looking at those links i'm a bit lost on how to use them:
.editorconfig
, Prettier config, or how do they detect what needs to be achieved)?Of course, long story short:
\t
to
, but only in source code files.{
) or removing extraneous indents (such as too much indentation in a continued statement or before a }
on a single line)?@timtebeek We should try to assert that the formatting auto-detection indeed is still part of the recipe run as implemented by the build plugins. At least as long as we offer that alternative.
Hi @Philzen ; sorry this took a while to get to; perhaps Slack is more convenient for follow up questions. :) To answer a quick few comments above:
org.openrewrite.java.format.TabsAndIndents
, optionally with a configured style using our Yaml format; that should also know when to insert newlines as you indicated.Thanks again for your support of the project!
I'll close this issue as it's not specific to the particular recipe in this module, and from the above it appears the mixed use of indentation styles appears to have factored in mostly, since we've not had any similar reports since.
What version of OpenRewrite are you using?
I can only assume this used
as i used the CLI command apparently has all current dependencies up-to-date and locally available. Attaching the full output here:
Full execution output
How are you running OpenRewrite?
Using the CLI command to upgrade to Spring Boot 2.7.x:
What is the smallest, simplest way to reproduce the problem?
Have a test file with a test method that is public and does not use-tab indentation.
What did you expect to see?
No tabs in an exclusively space indented file. Also, i would prefer it to respect the existing formatting – our formatting guidelines put certain Junit5 annotations on the same line. Basically, i would have only needed to replace
public
with an empty string, like this:What did you see instead?