{"id":15967116,"url":"https://github.com/itprokyle/pre-commit-hook-yamlfmt","last_synced_at":"2025-05-07T23:22:13.403Z","repository":{"id":44916385,"uuid":"449298168","full_name":"ITProKyle/pre-commit-hook-yamlfmt","owner":"ITProKyle","description":"YAML formatter for http://pre-commit.com","archived":false,"fork":false,"pushed_at":"2025-05-03T17:44:19.000Z","size":829,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-04T21:53:09.817Z","etag":null,"topics":["pre-commit"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ITProKyle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"ITProKyle","polar":"ITProKyle"}},"created_at":"2022-01-18T13:36:27.000Z","updated_at":"2025-05-03T14:33:49.000Z","dependencies_parsed_at":"2024-11-06T07:20:59.186Z","dependency_job_id":"d6070046-a38c-4681-8d72-9e2fe9488bab","html_url":"https://github.com/ITProKyle/pre-commit-hook-yamlfmt","commit_stats":{"total_commits":172,"total_committers":7,"mean_commits":"24.571428571428573","dds":"0.33720930232558144","last_synced_commit":"888deeadba44c39cf6fe03b10b653b7af08b57e6"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITProKyle%2Fpre-commit-hook-yamlfmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITProKyle%2Fpre-commit-hook-yamlfmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITProKyle%2Fpre-commit-hook-yamlfmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITProKyle%2Fpre-commit-hook-yamlfmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ITProKyle","download_url":"https://codeload.github.com/ITProKyle/pre-commit-hook-yamlfmt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252969049,"owners_count":21833402,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pre-commit"],"created_at":"2024-10-07T18:20:49.498Z","updated_at":"2025-05-07T23:22:13.372Z","avatar_url":"https://github.com/ITProKyle.png","language":"Python","funding_links":["https://github.com/sponsors/ITProKyle","https://polar.sh/ITProKyle"],"categories":[],"sub_categories":[],"readme":"# YAML formatter for pre-commit git hooks\n\n[![default](https://github.com/ITProKyle/pre-commit-hook-yamlfmt/actions/workflows/on-push.yml/badge.svg)](https://github.com/ITProKyle/pre-commit-hook-yamlfmt/actions/workflows/on-push.yml)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)\n[![GitHub Release](https://img.shields.io/github/v/release/ITProKyle/pre-commit-hook-yamlfmt)](https://github.com/ITProKyle/pre-commit-hook-yamlfmt/releases)\n[![renovate](https://img.shields.io/badge/enabled-brightgreen?logo=renovatebot\u0026logoColor=%2373afae\u0026label=renovate)](https://developer.mend.io/)\n\n\u003e [!NOTE]\n\u003e This project is a fork of [jumanjihouse/pre-commit-hook-yamlfmt](https://github.com/jumanjihouse/pre-commit-hook-yamlfmt).\n\nYAML formatter for [`pre-commit`].\n\nThis hook formats the indentation of YAML files and optionally aligns top-level colons.\n[`ruamel.yaml`] is used to roundtrip YAML files, preserving comments as much as possible.\n\n\u003e [!IMPORTANT]\n\u003e Each versioned release of this hook is pinned to an exact version of it's direct dependencies to limit unexpected changes.\n\n## Options\n\n| Option                                       | Default                  | Description                                         |\n| -------------------------------------------- | ------------------------ | --------------------------------------------------- |\n| `--allow-duplicate-keys/--no-duplicate-keys` | `--allow-duplicate-keys` | whether to allow duplicate keys                     |\n| `--colons/--no-colons`                       | `--no-colons`            | whether to align top-level colons                   |\n| `--implicit-start/--no-implicit-start`       | `implicit-start`         | whether to remove the explicit document start       |\n| `--mapping, -m`                              | `4`                      | number of spaces to indent mappings (dictionaries)  |\n| `--offset, -o`                               | `4`                      | number of spaces to offset the dash from sequences  |\n| `--preserve-quotes/--no-preserve-quotes`     | `--preserve-quotes`      | whether to keep existing string quoting             |\n| `--sequence, -s`                             | `6`                      | number of spaces to indent sequences (arrays/lists) |\n| `--width, -w`                                | `4096`                   | maximum line width                                  |\n\n\u003e [!CAUTION]\n\u003e If trying to use `--allow-duplicate-keys` to enable unpacking two anchors into a mapping (dictionary), this will not have the desired result.\n\u003e In fact, it can cause breakage without warning other than [`pre-commit`] showing the file was changed.\n\u003e\n\u003e When used with this scenario, the first anchor will remain but all other anchors will be removed.\n\u003e This is a flaw in [`ruamel.yaml`], not this hook.\n\n## How-to\n\n### Configure pre-commit\n\n#### Use defaults\n\nAdd to `.pre-commit-config.yaml` in your git repo:\n\n```yaml\n- repo: https://github.com/ITProKyle/pre-commit-hook-yamlfmt\n  rev: v0.2.1  # or specific tag\n  hooks:\n    - id: yamlfmt\n```\n\n\u003e [!TIP]\n\u003e If a pre-commit hook changes a file, the hook fails with a warning that files were changed.\n\nGiven this input:\n\n```yaml\nfoo:\n  bar:\n    - baz1\n    - baz2\n```\n\nThe default settings result in this output:\n\n```yaml\n---\nfoo:\n  bar:\n    - baz1\n    - baz2\n```\n\n#### Combine with `yamllint`\n\n`yamlfmt` only works with valid YAML files, so I recommend to use `yamllint` and `yamlfmt` together.\n\n```yaml\n- repo: https://github.com/adrienverge/yamllint.git\n  rev: v1.21.0  # or higher tag\n  hooks:\n    - id: yamllint\n      args: [--format, parsable, --strict]\n\n- repo: https://github.com/ITProKyle/pre-commit-hook-yamlfmt\n  rev: v0.2.1  # or specific tag\n  hooks:\n    - id: yamlfmt\n```\n\n#### Override defaults\n\nAdd to `.pre-commit-config.yaml` in your git repo:\n\n```yaml\n- repo: https://github.com/ITProKyle/pre-commit-hook-yamlfmt\n  rev: v0.2.1  # or specific tag\n  hooks:\n    - id: yamlfmt\n      args: [--mapping, '2', --sequence, '2', --offset, '0', --colons, --width, '150']\n```\n\n### Invoke pre-commit\n\n#### On every commit\n\nIf you want to invoke the checks as a git [`pre-commit`] hook, run:\n\n```console\n# Run on every commit.\npre-commit install\n```\n\n#### On demand\n\nIf you want to run the checks on-demand (outside of git hooks), run:\n\n```console\n# Run on-demand.\npre-commit run --all-files\n```\n\n## FAQs\n\n### Can I use `pip` to install this?\n\nNo. It is strictly a [`pre-commit`] hook.\n\n### Is this project related to [`yamlfmt`](https://pypi.org/project/yamlfmt/)?\n\nNo.\n\n[`pre-commit`]: http://pre-commit.com\n[`ruamel.yaml`]: https://yaml.readthedocs.io/en/latest/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitprokyle%2Fpre-commit-hook-yamlfmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitprokyle%2Fpre-commit-hook-yamlfmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitprokyle%2Fpre-commit-hook-yamlfmt/lists"}