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

Remove maven properties should remove comment #4554

Merged

Conversation

jonesbusy
Copy link
Contributor

@jonesbusy jonesbusy commented Oct 6, 2024

I saw in many project maven properties with an attached comment.

When running some recipes to remove properties the comment is left behind

I don't know how to fix it but I've implemented a test that demonstrates the issue

Example when cleanup property override (that are defined on a parent pom)

I would expect the TODO comment is also gone

Screenshot from 2024-10-06 07-43-46

Anything in particular you'd like reviewers to focus on?

Some help to implement it

Have you considered any alternatives or workarounds?

Not really

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@timtebeek timtebeek self-requested a review October 6, 2024 08:38
@timtebeek
Copy link
Contributor

Thanks for the report! Makes sense to also want to remove any preceding comments; I've made it optional in RemoveContentVisitor same as we did with removing empty ancestors. I'm on the fence a bit if we should make this the new default or not across the other usages. That might surprise folks, although in practice I think it's rare that this would lead to issues. Any insights there?

image

@timtebeek timtebeek added the enhancement New feature or request label Oct 6, 2024
@timtebeek timtebeek marked this pull request as ready for review October 6, 2024 09:20
@jonesbusy
Copy link
Contributor Author

My opinion it that is should be the default. I don't see any reason to keep existing comment when removing such tag.

I see that we filter Xml.Comment to the risk is close to zero

@knutwannheden
Copy link
Contributor

Since we in the end produce a diff, the developer can still decide to restore the comment, in the case that it also pertains to any subsequent elements. I would probably remove them by default.

In OpenRewrite we don't have any concept of trailing comments, but I think it could be interesting to build a trait or something similar which would allow recipes that remove elements to also remove the "associated" comments, which would typically be any preceding multi-line comment and trailing single-line comments.

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for kicking this off and the quick feedback (both) on changing the default. Applied this everywhere it made sense, except where we were replacing with a similar element.

@timtebeek timtebeek merged commit 094e714 into openrewrite:main Oct 6, 2024
2 checks passed
@jonesbusy jonesbusy deleted the remove/property-remove-comment branch October 6, 2024 10:22
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 this pull request may close these issues.

3 participants