yamlfix icon indicating copy to clipboard operation
yamlfix copied to clipboard

Yamlfix breaks multiline strings, idempotency problems

Open scoopex opened this issue 7 months ago • 0 comments

The current release (1.16.0/47039c9) breaks multiline strings.

See:

$ git clone [email protected]:SovereignCloudStack/hardware-landscape.git
$ git checkout improve_yaml
$ make lint-fix
.. .
$ make lint-fix
...
./environments/custom/roles/scs-serial-terminals/tasks/main.yml
[+] YamlFix: Fixing files
Traceback (most recent call last):
  File "/home//src/github/redacted/scs/hardware-landscape/venv/bin/yamlfix", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/yamlfix/entrypoints/cli.py", line 119, in cli
    fixed_code, changed = services.fix_files(files_to_fix, check, config)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/yamlfix/services.py", line 83, in fix_files
    fixed_source = fix_code(source, config)
                   ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/yamlfix/services.py", line 162, in fix_code
    source_code = fixer.fix(source_code=source_code)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/yamlfix/adapters.py", line 363, in fix
    source_code = fixer(source_code)
                  ^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/yamlfix/adapters.py", line 381, in _ruamel_yaml_fixer
    for source_dict in source_dicts:
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/main.py", line 477, in load_all
    yield constructor.get_data()
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/constructor.py", line 134, in get_data
    return self.construct_document(self.composer.get_node())
                                   ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/composer.py", line 63, in get_node
    return self.compose_document()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/composer.py", line 96, in compose_document
    node = self.compose_node(None, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/composer.py", line 140, in compose_node
    node = self.compose_sequence_node(anchor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/composer.py", line 184, in compose_sequence_node
    node.value.append(self.compose_node(node, index))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/composer.py", line 142, in compose_node
    node = self.compose_mapping_node(anchor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/composer.py", line 222, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/composer.py", line 142, in compose_node
    node = self.compose_mapping_node(anchor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/composer.py", line 215, in compose_mapping_node
    while not self.parser.check_event(MappingEndEvent):
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/parser.py", line 150, in check_event
    self.current_event = self.state()
                         ^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/parser.py", line 636, in parse_block_mapping_key
    if self.scanner.check_token(KeyToken):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/scanner.py", line 1827, in check_token
    self._gather_comments()
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/scanner.py", line 1869, in _gather_comments
    self.fetch_more_tokens()
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/scanner.py", line 290, in fetch_more_tokens
    return self.fetch_value()
           ^^^^^^^^^^^^^^^^^^
  File "/home//src/github/redacted/scs/hardware-landscape/venv/lib/python3.12/site-packages/ruyaml/scanner.py", line 665, in fetch_value
    raise ScannerError(
ruyaml.scanner.ScannerError: mapping values are not allowed here
  in "<unicode string>", line 26, column 21:
             echo "ERROR: not exactly on session available"
                        ^ (line: 26)

$ git diff ./environments/custom/roles/scs-serial-terminals/tasks/main.yml

....
diff --git a/environments/custom/roles/scs-serial-terminals/tasks/main.yml b/environments/custom/roles/scs-serial-terminals/tasks/main.yml
index 2339689..8677cb5 100644
--- a/environments/custom/roles/scs-serial-terminals/tasks/main.yml
+++ b/environments/custom/roles/scs-serial-terminals/tasks/main.yml
@@ -1,6 +1,5 @@
....
     content: |
-      #!/bin/bash
-
+        #!/bin/bash
       ident="scs_serial_access"
       cfg="/etc/screenrc_serial"
       logdir="/var/log/screen"
-

scoopex avatar Jul 07 '24 16:07 scoopex