Skip to content

Flow collections always wrap at >80 characters, regardless of lineWidth option #507

@TheBITLINK

Description

@TheBITLINK

Describe the bug
When using the flow collection style, collections always seem to wrap at around 80 characters, regardless of the lineWidth option:

blockCollection:
  aKey: hello
  anotherKey: world
  yetAnotherKey: "!!!"
listOfFlowCollection:
  - {
      aKey: hello,
      anotherKey: world,
      yetAnotherKey: "!!!",
      oneMoreKey: "!!!!!!!!"
    }
  - {
      aKey: hello,
      anotherKey: world,
      yetAnotherKey: "!!!",
      oneMoreKey: "!!!!!!!!"
    }
flowColTwo:
  - { aKey: hello, bKey: world, cKey: "!!!" }
  - { aKey: hello, bKey: world, cKey: "!!!" }
  - { aKey: hello, bKey: world, cKey: "!!!", dKey: "!" }

To Reproduce

  function serialize() {
    const doc = new YAML.Document({
      blockCollection: {
        aKey: 'hello',
        anotherKey: 'world',
        yetAnotherKey: '!!!'
      },
      listOfFlowCollection: [
        { aKey: 'hello', anotherKey: 'world', yetAnotherKey: '!!!', oneMoreKey: '!!!!!!!!'  },
        { aKey: 'hello', anotherKey: 'world', yetAnotherKey: '!!!', oneMoreKey: '!!!!!!!!'  },
      ],
      flowColTwo: [
        { aKey: 'hello', bKey: 'world', cKey: '!!!'  },
        { aKey: 'hello', bKey: 'world', cKey: '!!!'  },
        { aKey: 'hello', bKey: 'world', cKey: '!!!',  dKey: '!' },
      ]
    })
    YAML.visit(doc, {
      Pair(_, pair: any) {
        if (pair.key?.value === 'listOfFlowCollection' || pair.key?.value === 'flowColTwo')  {
          for (const i of pair.value.items) {
            i.flow = true
          }
        }
      }
    })
    return doc.toString({ lineWidth: 120 })
  }

Expected behaviour
Flow collections respect the lineWidth option and wrap at 120 characters instead of 80 (or not wrap at all if lineWidth is 0)

blockCollection:
  aKey: hello
  anotherKey: world
  yetAnotherKey: "!!!"
listOfFlowCollection:
  - { aKey: hello, anotherKey: world, yetAnotherKey: "!!!", oneMoreKey: "!!!!!!!!" }
  - { aKey: hello, anotherKey: world, yetAnotherKey: "!!!", oneMoreKey: "!!!!!!!!" }
flowColTwo:
  - { aKey: hello, bKey: world, cKey: "!!!" }
  - { aKey: hello, bKey: world, cKey: "!!!" }
  - { aKey: hello, bKey: world, cKey: "!!!", dKey: "!" }

Versions (please complete the following information):

  • Environment: Chrome 119.0.6045.159
  • yaml: 2.3.4

Additional context
The same issue manifests when using collectionStyle: 'flow' in the toString() options, so it's not specific to mixed style.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions