Giter Club home page Giter Club logo

Comments (4)

braydonk avatar braydonk commented on June 2, 2024 2

Thanks for opening an issue. This looks like it's probably caused by the same thing as I've been tracking in #86, which I haven't been able to resolve yet due to its complexity.

from yamlfmt.

bewee-i avatar bewee-i commented on June 2, 2024 1

This is not limited to trailing whitespaces in the last line of a folded string:

foo: >
  lorem 
  ipsum

is being formated to

foo: "lorem \nipsum\n"

from yamlfmt.

mikelorant avatar mikelorant commented on June 2, 2024 1

Can also confirmed this is happening with normal block scalars.

Before

block: |
  key: value (single whitespace appended)

After

block: "key: value \n"

Expected

block: |
  key: value (whitespace removed)

If there is no trailing whitespace, everything words as expected. As per @bewee-i any line with a trailing whitespace will cause this occur, it is not limited to the last line.

from yamlfmt.

braydonk avatar braydonk commented on June 2, 2024

Thank you for the additional example.

On the root issue #86 I added an explanation for why this bug occurs, but I'll copy that explanation here for visibility:

This is caused by the hack around the fact that yaml.v3 doesn't retain plain line-break information. yamlfmt will insert a magic string before being serialized into yaml.v3's node structure. Then after the new output is produced, we use the magic strings to put them back in. However, one place that newline information will actually be retained is in block scalars. So the magic line string being thrown on there messes with the serialization. I can't think of a way around this without somehow getting rid of the hack. I've tried in the past to fix this in yaml.v3 but I came up short. I've been wanting to build my own yaml parser instead to rid myself of yaml.v3 in general, and in that case this and many other fixes/features I've wanted to implement would be possible. Haven't had the time to invest to make that happen though.

from yamlfmt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.