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

Discussion/question: Is the default application of UseTextBlocks too 'opinionated' ? #260

Closed
jjank opened this issue Jul 18, 2023 · 6 comments · Fixed by #273
Closed

Discussion/question: Is the default application of UseTextBlocks too 'opinionated' ? #260

jjank opened this issue Jul 18, 2023 · 6 comments · Fixed by #273
Labels
enhancement New feature or request

Comments

@jjank
Copy link

jjank commented Jul 18, 2023

Hi there,

this is not a bug, merely a question / point of discussion:

While executing a Spring Boot 3.1 migration (from 3.0.8) I noticed that UseTextBlocks did a couple of changes:

$ mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \
  -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE \
  -Drewrite.activeRecipes=org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1

Changes have been made to ****.java by:
    org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1
         org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0
             org.openrewrite.java.migrate.UpgradeToJava17
                 org.openrewrite.java.migrate.lang.UseTextBlocks: {convertStringsWithoutNewlines=true}

(version was rewrite:5.3.1)

The diff looks a little bit...unfortunate in my opinion:

Screenshot 2023-07-18 at 12 51 16

My question is: Is the default inclusion of org.openrewrite.java.migrate.lang.UseTextBlocks in org.openrewrite.java.migrate.UpgradeToJava17 really desirable? Because technically nothing forces developers too use text blocks (don't get me wrong, I love them). It's a 'stylistic' change but nothing 'functional'.

I do realize that this also comes down to personal preference but my personal opinion is that it introduces changes that might not be desirable in every situation.

Thanks for your thoughts about this 👍

@timtebeek
Copy link
Contributor

Thanks for bringing up this concern @jjank ! It's indeed a known limitation of the recipe (#261) which we still hope to resolve such that it does not cause any issues for our users.

I do agree that perhaps we should not be making changes if we recognize such a case, such that we can still add in some text blocks, but make it an optional (default false) to also add such known-incomplete text blocks. Then when we include the recipe we have that set to the default, but people can still override the default to get even more text blocks. Would that be acceptable here?

Alternatively we could try to write a recipe that first turns such string concatenation into a formatted String, which would then be easier to convert into a text block. But that might also have some challenges to get right.

@timtebeek timtebeek moved this to Backlog in OpenRewrite Jul 18, 2023
@timtebeek timtebeek added the enhancement New feature or request label Jul 18, 2023
@jjank
Copy link
Author

jjank commented Jul 18, 2023

but people can still override the default to get even more text blocks. Would that be acceptable here?

In my opinion: yes. Giving users a way to easily "opt-out" would be a good compromise 👍

@timtebeek
Copy link
Contributor

Then let's have this ticket be the focus point of adding such an optional back-off, whereas we keep #261 with a focus on improving the recipe itself, such that a back-off option is not necessary as often.

@timtebeek
Copy link
Contributor

And of course as always: let me know if you'd like to help out either with this one or #261 😇

@yeikel
Copy link
Contributor

yeikel commented Aug 7, 2023

For what it is worth, I think that not using TextBlocks in favor of the concatenation is a code smell

timtebeek added a commit that referenced this issue Aug 16, 2023
timtebeek added a commit that referenced this issue Aug 16, 2023
* Do not partially use text blocks

Fixes #260

* Restore original order

* Restore original order

* Clear out duplication in recursive function

* Move function down; IDE keeps moving this
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenRewrite Aug 16, 2023
@timtebeek
Copy link
Contributor

We'll continue to look for a proper fix in #261 , as discussed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants