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

multiline string gets turned into long line #240

Open
ggoretkin-bdai opened this issue May 3, 2023 · 6 comments
Open

multiline string gets turned into long line #240

ggoretkin-bdai opened this issue May 3, 2023 · 6 comments
Labels
bug Something isn't working help wanted Extra attention is needed upstream

Comments

@ggoretkin-bdai
Copy link

Description and Current Behavior

yamlfix turns

---
jobs:
  run_jobs:
    steps:
      - name: Upload coverage to Codecov
        with:
          files: ./projects/aaaaaaaaaaaaaaaaa/ws/build/formation_planner/coverage.xml,
            ./projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml,
            ./projects/bbbb_examples/ws/build/bbbb_examples/coverage.xml,
            ./projects/ccccccccccccccccccc/ws/build/diagnose_repair/coverage.xml,
            projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml,
            ./ws/build/abcd_abc/coverage.xml, ./ws/build/bbbb_bbbbter/coverage.xml,
            ./ws/build/abcd_abc_wrappers/coverage.xml

into

---
jobs:
  run_jobs:
    steps:
      - name: Upload coverage to Codecov
        with:
          files: ./projects/aaaaaaaaaaaaaaaaa/ws/build/formation_planner/coverage.xml,
            ./projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml,
            ./projects/bbbb_examples/ws/build/bbbb_examples/coverage.xml, ./projects/ccccccccccccccccccc/ws/build/diagnose_repair/coverage.xml,
            projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml,
            ./ws/build/abcd_abc/coverage.xml, ./ws/build/bbbb_bbbbter/coverage.xml,
            ./ws/build/abcd_abc_wrappers/coverage.xml

Desired behavior

breakable lines should not exceed the default column width

Environment

$ python -c "import yamlfix.version; print(yamlfix.version.version_info())"
------------------------------------------------------------------
     yamlfix: 1.9.0
     Python: 3.10.6
     Platform: Linux-5.19.0-40-generic-x86_64-with-glibc2.35
------------------------------------------------------------------
@ggoretkin-bdai ggoretkin-bdai added the bug Something isn't working label May 3, 2023
@lyz-code
Copy link
Owner

lyz-code commented May 4, 2023

Hi @ggoretkin-bdai thanks for taking the time to open an issue. Maybe I'm understanding you wrong but the snippet you provided is not a valid yaml way to break long lines. You need to use the > or | operators. For example the next snippet is untouched by yamlfix:

---
jobs:
  run_jobs:
    steps:
      - name: Upload coverage to Codecov
        with:
          files: >
            ./projects/aaaaaaaaaaaaaaaaa/ws/build/formation_planner/coverage.xml,
            ./projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml,
            ./projects/bbbb_examples/ws/build/bbbb_examples/coverage.xml,
            ./projects/ccccccccccccccccccc/ws/build/diagnose_repair/coverage.xml,
            projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml,
            ./ws/build/abcd_abc/coverage.xml, ./ws/build/bbbb_bbbbter/coverage.xml,
            ./ws/build/abcd_abc_wrappers/coverage.xml

In case you're not familiar with these operators here is a little cheatsheet

Break long lines

  • Use > most of the time: interior line breaks are stripped out, although you
    get one at the end:

    key: >
      Your long
      string here.
  • Use | if you want those line breaks to be preserved as \n (for instance,
    embedded markdown with paragraphs):

    key: |
      ### Heading
    
      * Bullet
      * Points
  • Use >- or |- instead if you don't want a line break appended at the end.

@lyz-code lyz-code closed this as completed May 4, 2023
@ggoretkin-bdai
Copy link
Author

Thanks for the quick reply, and the explanation. I believe there is still something going on that I could use help understanding. The exact situation I am running into is:

jobs:
  run_jobs:
    steps:
      - name: Upload coverage to Codecov
        with:
          files: ./projects/aaaaaaaaaaaaaaaaa/ws/build/formation_planner/coverage.xml, ./projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml, ./projects/bbbb_examples/ws/build/bbbb_examples/coverage.xml, ./projects/ccccccccccccccccccc/ws/build/diagnose_repair/coverage.xml, projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml, ./ws/build/abcd_abc/coverage.xml, ./ws/build/bbbb_bbbbter/coverage.xml, ./ws/build/abcd_abc_wrappers/coverage.xml

Note that it is a single long line at the end. yamlfix turns it into

---
jobs:
  run_jobs:
    steps:
      - name: Upload coverage to Codecov
        with:
          files: ./projects/aaaaaaaaaaaaaaaaa/ws/build/formation_planner/coverage.xml,
            ./projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml,
            ./projects/bbbb_examples/ws/build/bbbb_examples/coverage.xml, ./projects/ccccccccccccccccccc/ws/build/diagnose_repair/coverage.xml,
            projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml,
            ./ws/build/abcd_abc/coverage.xml, ./ws/build/bbbb_bbbbter/coverage.xml,
            ./ws/build/abcd_abc_wrappers/coverage.xml

From that I inferred some things about YAML that were not true (thank you for pointing out the >).

@ggoretkin-bdai
Copy link
Author

Furthermore, when I give this to yamlfix

---
jobs:
  run_jobs:
    steps:
      - name: Upload coverage to Codecov
        with:
          files: >
            ./projects/aaaaaaaaaaaaaaaaa/ws/build/formation_planner/coverage.xml,
            ./projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml,
            ./projects/bbbb_examples/ws/build/bbbb_examples/coverage.xml, ./projects/ccccccccccccccccccc/ws/build/diagnose_repair/coverage.xml,
            projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml,
            ./ws/build/abcd_abc/coverage.xml, ./ws/build/bbbb_bbbbter/coverage.xml,
            ./ws/build/abcd_abc_wrappers/coverage.xml

it becomes

---
jobs:
  run_jobs:
    steps:
      - name: Upload coverage to Codecov
        with:
          files: >-
            ./projects/aaaaaaaaaaaaaaaaa/ws/build/formation_planner/coverage.xml,
            ./projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml,
            ./projects/bbbb_examples/ws/build/bbbb_examples/coverage.xml, ./projects/ccccccccccccccccccc/ws/build/diagnose_repair/coverage.xml,
            projects/aaaaaaaaaaaaaaaaa/ws/build/aaaaaaaaaaaaaaaaa_abc/coverage.xml,
            ./ws/build/abcd_abc/coverage.xml, ./ws/build/bbbb_bbbbter/coverage.xml,
            ./ws/build/abcd_abc_wrappers/coverage.xml

> becomes >- . I also expected that the default line length of 80 chars would force each path on its own line.

@lyz-code
Copy link
Owner

lyz-code commented May 4, 2023

The > to >- is not a big deal because it's always best not to have the \n at the end of the string.

I can reproduce the long line not being handled. It seems that the string ./projects/bbbb_examples/ws/build/bbbb_examples/coverage.xml, is smaller than 80 characters and therefore it doesn't know how to split it. The issue can be either in the patch_sequence_style function or upstream from ruyaml which we use to handle the long string splitting

@lyz-code lyz-code reopened this May 4, 2023
@lyz-code lyz-code added the help wanted Extra attention is needed label May 4, 2023
@millin
Copy link

millin commented Jun 15, 2023

Apparently it's a bug in the ruyaml side, but it looks like it's dead

@rusmux
Copy link

rusmux commented Feb 6, 2024

@lyz-code How can I avoid formatting list items? For example:

build:
  stage: build
  before_script:
    - *docker_login
  script:
    - DOCKER_BUILDKIT=1 docker build .
      --cache-from $CI_REGISTRY_IMAGE:latest
      --platform=linux/amd64
      --network=host
      --progress=plain
      --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA

Transformed into:

build:
  stage: build
  before_script:
    - *docker_login
  script:
    - DOCKER_BUILDKIT=1 docker build . --cache-from $CI_REGISTRY_IMAGE:latest --platform=linux/amd64 --network=host --progress=plain
      --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed upstream
Projects
None yet
Development

No branches or pull requests

4 participants