Skip to content

Conversation

jonesbusy
Copy link
Contributor

@jonesbusy jonesbusy commented Aug 7, 2024

Just demonstrate it doesn't works as expected (or I didn't understood the recipe).

Instead of commenting out the property it's removed.

issue

What's changed?

What's your motivation?

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

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

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

@jonesbusy jonesbusy changed the title Fix CommentOutProperty to work with single keys fix: CommentOutProperty to work with single keys Aug 7, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • rewrite-java/src/main/java/org/openrewrite/java/table/ClasspathTypeCount.java
    • lines 47-47

@timtebeek
Copy link
Member

timtebeek commented Aug 7, 2024

Thanks for the runnable example here @jonesbusy ! Had a brief look, and I suspect there's an logical error in the recipe.

As a bit of background: comments are not floating elements, but attached to the next LST element. That allows them to move with the code, as opposed to having to always check of and move both with any restructuring. In this case, it seems the recipe has made the assumption that we can remove the comment, and add it to the "next" element. But in your case there is no next element, so the comment is accidentally lost.

What we should be doing here (I think) is to add any left over comment to the eof of the matching document / documents (TBD), via an additional vistDocument(s) override. That should then make sure we don't accidentally lose any commented out elements at the end of a doc. I hope that's clear!

@timtebeek timtebeek added the good first issue Good for newcomers label Aug 7, 2024
@jonesbusy
Copy link
Contributor Author

Thanks for the hint. Really helpful. I will try to take a look at it and perform also more test when the key is not the last element of the document

@jonesbusy jonesbusy force-pushed the bugfix/yaml-comment-out branch from 1f3d17f to ec5e0aa Compare August 7, 2024 13:22
github-actions[bot]

This comment was marked as off-topic.

@jonesbusy
Copy link
Contributor Author

I did a tentative to implement visitDocument. Not sure if it's the best approach (and if I understand it completly).

But at least the tests added are passing now.

Any other advice appreciated

@timtebeek timtebeek marked this pull request as ready for review August 7, 2024 15:52
@timtebeek timtebeek self-requested a review August 7, 2024 15:52
Copy link
Member

@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 taking this on! Exactly what I had in mind indeed; I've added & fixed another test case where there might be multiple documents, and with that I think we're good to merge once the tests pass.

@timtebeek timtebeek merged commit b453525 into openrewrite:main Aug 7, 2024
2 checks passed
@jonesbusy jonesbusy deleted the bugfix/yaml-comment-out branch August 7, 2024 17:49
@jonesbusy
Copy link
Contributor Author

Thanks for the fixed and merge! Much appreciated

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

Successfully merging this pull request may close these issues.

2 participants