macisamuele / language-formatters-pre-commit-hooks

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

Initial indent in yaml #132

Closed hdadhich01 closed 1 year ago

hdadhich01 commented 1 year ago

My local YAML formatter places an initial indent after the parent keyword in a .pre-commit-config.yaml file. The pretty-format-yaml hook formats it differently. I was wondering what the reason was for the discrepancy.

Local Formatter

repos:
  - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
    rev: v2.5.0
    hooks:
      - id: pretty-format-yaml
        args: [--autofix]

Hook Formatter

repos:
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
  rev: v2.5.0
  hooks:
  - id: pretty-format-yaml
    args: [--autofix]
macisamuele commented 1 year ago

Most probably the discrepancy is caused by the fact that pre-commit hooks create the python virtual environment with all the required dependencies on their first run, after that the virtual environment is just reused and not recreated. The same applies on the CI, with the only difference that the environment is always clean, hence the new version of the direct and indirect dependencies are fetched.

Are you able to reproduce the same issue after running pre-commit clean and then running the pre-commit hooks again?

hdadhich01 commented 1 year ago

Yes, seems to perform the same despite cleaning the hook environments.

macisamuele commented 1 year ago

Sorry, I might have missed the detail that your local-formatter is not a local-run of the pre-commit hook.

What I would deduce is that the two pre-commit hooks are attempting to enforce different styles.

I think that if the tool were to expose --offset configuration you could be able to achieve "equal formatting". Going to be implementing it in #143

hdadhich01 commented 1 year ago

Great, thanks! Could you put out a release tag sometime soon?