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

Dumper can generate bad YAML #28

Open
archoversight opened this issue Nov 30, 2020 · 0 comments
Open

Dumper can generate bad YAML #28

archoversight opened this issue Nov 30, 2020 · 0 comments

Comments

@archoversight
Copy link

Hello,

I am using the old upstream project with a pre-commit hook: https://github.com/archoversight/pre-commit-hook-yamlfmt/tree/feature/explicit_end

However when I use the following configuration:

        yaml.indent(
            mapping=2,
            sequence=2,
            offset=2,
            )

Which I would hope would format the following:

---
fail_fast: true
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks.git
    rev: v3.2.0
    hooks:
      - id: no-commit-to-branch
      - id: check-json
      - id: check-yaml
      - id: end-of-file-fixer
      - id: mixed-line-ending
      - id: trailing-whitespace

  - repo: https://github.com/archoversight/pre-commit-hook-yamlfmt.git
    rev: 0.1.0-explicit
    hooks:
      - id: yamlfmt
        args: [--mapping, '4', --sequence, '4', --offset, '2', --explicit_end, --explicit_start]
...

As:

---
fail_fast: true
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks.git
    rev: v3.2.0
    hooks:
      - id: no-commit-to-branch
      - id: check-json
      - id: check-yaml
      - id: end-of-file-fixer
      - id: mixed-line-ending
      - id: trailing-whitespace

  - repo: https://github.com/archoversight/pre-commit-hook-yamlfmt.git
    rev: 0.1.0-explicit
    hooks:
      - id: yamlfmt
        args: [--mapping, '2', --sequence, '2', --offset, '2', --explicit_end, --explicit_start]
...

However instead it formats it as follows:

---
fail_fast: true
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks.git
  rev: v3.2.0
  hooks:
    - id: no-commit-to-branch
    - id: check-json
    - id: check-yaml
    - id: end-of-file-fixer
    - id: mixed-line-ending
    - id: trailing-whitespace

  - repo: https://github.com/archoversight/pre-commit-hook-yamlfmt.git
  rev: 0.1.0-explicit
  hooks:
    - id: yamlfmt
    args: [--mapping, '2', --sequence, '2', --offset, '2', --explicit_end, --explicit_start]
...

For some reason it fails to take into account the fact that there is already an offset from the - before printing the next mapping.

Setting the sequence to 4 does seem to solve the problem, but it feels weird that this would be required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant