Skip to content

feat: preserve line breaks from original input#412

Merged
goccy merged 2 commits intogoccy:masterfrom
mcwarman:feature/preserve-linebreaks
Nov 2, 2024
Merged

feat: preserve line breaks from original input#412
goccy merged 2 commits intogoccy:masterfrom
mcwarman:feature/preserve-linebreaks

Conversation

@mcwarman
Copy link
Copy Markdown
Contributor

Motivation

Preserve the line breaks from input.

We use this project as dependency in a project that round trips YAML, this attempts to try and preserve the formatting. It will only ever add one line break between lines regardless of input.

Changes

  • add checkLineBreak method that uses the previous token to calculate if there should be a line break
  • account for token.SequenceEntryType using the previous token of that.
  • ensure multiline strings are accounted for in the logic
  • add a new table test
  • update existing test to validate string output has changed
  • update existing tests to output differences on failure

Checks

  • Describe the purpose for which you created this PR.
  • Create test code that corresponds to the modification

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Dec 15, 2023

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.03%. Comparing base (0640a15) to head (7e17e11).
Report is 30 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #412      +/-   ##
==========================================
+ Coverage   76.02%   78.03%   +2.00%     
==========================================
  Files          13       18       +5     
  Lines        4692     5922    +1230     
==========================================
+ Hits         3567     4621    +1054     
- Misses        866     1028     +162     
- Partials      259      273      +14     

@mcwarman
Copy link
Copy Markdown
Contributor Author

mcwarman commented Jan 2, 2024

@goccy I'd be interested to get your thoughts on this.

If you specifically have reservations/thoughts on how the change could be behind a feature flag for backwards compatibility, let me know.

Comment thread ast/ast.go Outdated
@olblak
Copy link
Copy Markdown

olblak commented Apr 29, 2024

@goccy Kindly pinging you in cased you missed the previous notification.
It would be awesome to see this pullrequest moving forward

@olblak
Copy link
Copy Markdown

olblak commented Nov 1, 2024

Hi @goccy,

I could see you spend some time recently on this great library.
Would you have some time to accept this pullrequest?
Thanks in advance

@goccy
Copy link
Copy Markdown
Owner

goccy commented Nov 1, 2024

LGTM 👍 Please fix typo

@goccy goccy added reviewed enhancement New feature or request labels Nov 1, 2024
Co-authored-by: Hilmar Falkenberg <hilmar.falkenberg@sap.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants