jumanjihouse / pre-commit-hook-yamlfmt

YAML formatter for http://pre-commit.com
MIT License
61 stars 28 forks source link

mapping values are not allowed here #44

Open bilyboy785 opened 1 year ago

bilyboy785 commented 1 year ago

Pre-commit-config :

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
  rev: 0.2.2
  hooks:
  - id: yamlfmt
    name: YAML FMT
    args: [--mapping, '2', --sequence, '2', --offset, '0', --width, '250']

Example YAML file with indentation problem :

images:
    - name: eu.gcr.io/xxxxxxxxxx/xxxx/xxxxxxxxxxx/xxxxxxxx
         newTag: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Error when i commit :

YAML FMT.................................................................Failed
- hook id: yamlfmt
- exit code: 1

api-medicaments/overlays/dev/kustomization.yamlTraceback (most recent call last):
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/bin/yamlfmt", line 181, in <module>
    FORMATTER.format(file_name)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/bin/yamlfmt", line 137, in format
    FORMATTER.parse_file(path)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/bin/yamlfmt", line 147, in parse_file
    self.content = list(self.yaml.load_all(stream))
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/main.py", line 461, in load_all
    yield constructor.get_data()
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/constructor.py", line 114, in get_data
    return self.construct_document(self.composer.get_node())
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 66, in get_node
    return self.compose_document()
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 99, in compose_document
    node = self.compose_node(None, None)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 143, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 223, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 141, in compose_node
    node = self.compose_sequence_node(anchor)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 185, in compose_sequence_node
    node.value.append(self.compose_node(node, index))
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 143, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 223, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/composer.py", line 113, in compose_node
    if self.parser.check_event(AliasEvent):
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/parser.py", line 146, in check_event
    self.current_event = self.state()
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/parser.py", line 630, in parse_block_mapping_value
    if self.scanner.check_token(ValueToken):
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/scanner.py", line 1796, in check_token
    self._gather_comments()
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/scanner.py", line 1838, in _gather_comments
    self.fetch_more_tokens()
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/scanner.py", line 288, in fetch_more_tokens
    return self.fetch_value()
  File "/Users/mbouillaud/.cache/pre-commit/repoge4is5u9/py_env-python3.10/lib/python3.10/site-packages/ruamel/yaml/scanner.py", line 657, in fetch_value
    raise ScannerError(
ruamel.yaml.scanner.ScannerError: mapping values are not allowed here
  in "api-medicaments/overlays/dev/kustomization.yaml", line 20, column 15
mglants commented 1 year ago

+1