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

Merge yaml test for inline comments retention #4365

Conversation

johnpaulms
Copy link
Contributor

@johnpaulms johnpaulms commented Jul 30, 2024

What's changed?

Added test case to test inline comment retention for mergeyaml recipe

What's your motivation?

We have same issue as described here

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

Nothing as of now.

Anyone you would like to review specifically?

@timtebeek @pstreef to review this test case

Have you considered any alternatives or workarounds?

There is no work around for this issue. Developers want to retain the comments in their yaml file.

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

@timtebeek timtebeek marked this pull request as draft July 30, 2024 18:28
@timtebeek timtebeek requested a review from pstreef July 30, 2024 18:28
@timtebeek timtebeek added the bug Something isn't working label Jul 30, 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-gradle/src/main/groovy/RewriteSettings.groovy
    • lines 31-36

@timtebeek
Copy link
Contributor

Thanks for the helpful test here @johnpaulms ! What I can see from stepping through with the debugger is that the comment is attached to the document.end, as opposed to the document.block.entries[0], which it why it appears to shift. If there were an element after that sequence, then the comment moves to the prefix of the next element. We'l have to mimic that and move the end to a prefix accordingly to have that preserve it's location. @pstreef is this something you can fit in there?

@pstreef pstreef changed the base branch from main to fix/merge-yaml-block-indentation July 31, 2024 06:35
@pstreef pstreef marked this pull request as ready for review July 31, 2024 06:35
@pstreef pstreef changed the base branch from fix/merge-yaml-block-indentation to main July 31, 2024 06:36
@pstreef pstreef changed the base branch from main to fix/merge-yaml-block-indentation July 31, 2024 06:37
@pstreef
Copy link
Contributor

pstreef commented Jul 31, 2024

merging this into my branch so I can take it along there

@pstreef pstreef merged commit 97b2868 into openrewrite:fix/merge-yaml-block-indentation Jul 31, 2024
@johnpaulms johnpaulms deleted the merge-yaml-test branch July 31, 2024 15:22
jevanlingen pushed a commit that referenced this pull request Nov 22, 2024
* Added test cases to check inline comment retention.

* Updated issue number to check inline comment retention.

---------

Co-authored-by: j0m17kw <[email protected]>
Co-authored-by: Peter Streef <[email protected]>
jevanlingen pushed a commit that referenced this pull request Nov 25, 2024
* Added test cases to check inline comment retention.

* Updated issue number to check inline comment retention.

---------

Co-authored-by: j0m17kw <[email protected]>
Co-authored-by: Peter Streef <[email protected]>
timtebeek added a commit that referenced this pull request Nov 25, 2024
* fix: `MergeYaml` block indentation not as expected

* Indication where things need to change

* calculate indentation

* add todo

* Make it work with variable indent

* Fix for sequences

* cleanup

* cleanup

* comments

* extract method

* revert

* revert

* Merge yaml test for inline comments retention (#4365)

* Added test cases to check inline comment retention.

* Updated issue number to check inline comment retention.

---------

Co-authored-by: j0m17kw <[email protected]>
Co-authored-by: Peter Streef <[email protected]>

* revert

* Revert all to main (to start again)

* Make multiline scalars work

* Cleanup

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Add extra test `addPropertyWitCommentAboveLastLine`

* Improve IndentsVisitor, so merged multiline scalars work too

* Small improvements

* Apply formatter

* Consistently use the same style of import for nested classes

* Reuse local variable `value` instead of repeated `incomingEntry.getValue()`

* Small improvements

---------

Co-authored-by: johnpaulms <[email protected]>
Co-authored-by: j0m17kw <[email protected]>
Co-authored-by: lingenj <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tim te Beek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants