macisamuele / language-formatters-pre-commit-hooks

Collection of custom pre-commit hooks.
Apache License 2.0
115 stars 58 forks source link

Option to disable root-level sequence indentation #174

Closed denys-kochetkov closed 1 year ago

denys-kochetkov commented 1 year ago

We run pre-commit YAML formatting on our Ansible playbooks with the following configuration:

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
    rev: v2.9.0
    hooks:
      - id: pretty-format-yaml
        args: [--autofix, --preserve-quotes, --indent, '2', --offset, '2']

By default, all sequences are indented, including root-level sequences. So this YAML file:

- a: 1
- b: 2

Is converted to this with two leading whitespaces:

  - a: 1
  - b: 2

This was addressed in this Stackoverflow question with a custom transform function, would be nice to have something similar here as well.

macisamuele commented 1 year ago

I think that if you remove the offset definition you will obtain the desired output.

I'll keep this open for a few days to give space for conversion before closing this, as it looks like an already supported feature.