Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
YAML formatter for http://pre-commit.com
https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
formatter pre-commit yamllint
Last synced: about 2 months ago
JSON representation
YAML formatter for http://pre-commit.com
- Host: GitHub
- URL: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
- Owner: jumanjihouse
- License: mit
- Created: 2020-03-25T17:24:42.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-12T20:25:56.000Z (11 months ago)
- Last Synced: 2024-08-13T07:08:37.349Z (5 months ago)
- Topics: formatter, pre-commit, yamllint
- Language: Python
- Size: 44.9 KB
- Stars: 60
- Watchers: 4
- Forks: 28
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - jumanjihouse/pre-commit-hook-yamlfmt - YAML formatter for http://pre-commit.com (Python)
README
# YAML formatter for pre-commit git hooks
YAML formatter for [pre-commit](http://pre-commit.com).
This hook formats the indentation of YAML files and
optionally aligns top-level colons.
It uses [ruamel.yaml](https://yaml.readthedocs.io/en/latest/)
to do the heavy lifting and preserve comments within YAML files.- [How-to](#how-to)
- [Configure pre-commit](#configure-pre-commit)
- [Use defaults](#use-defaults)
- [Combine with `yamllint`](#combine-with-yamllint)
- [Override defaults](#override-defaults)
- [Invoke pre-commit](#invoke-pre-commit)
- [On every commit](#on-every-commit)
- [On demand](#on-demand)
- [Contributing](#contributing)
- [Testing](#testing)
- [License](#license)## How-to
### Configure pre-commit
#### Use defaults
Add to `.pre-commit-config.yaml` in your git repo:
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.1 # or other specific tag
hooks:
- id: yamlfmt:bulb: If a pre-commit hook changes a file,
the hook fails with a warning that files were changed.The default settings are:
- `mapping`: 4 spaces
- `sequence`: 6 spaces
- `offset`: 4 spaces
- `colons`: do _not_ align top-level colons
- `width`: None (use ruamel default)Given this input:
foo:
bar:
- baz1
- baz2The default settings result in this output:
---
foo:
bar:
- baz1
- baz2#### Combine with `yamllint`
`yamlfmt` only works with valid YAML files, so
I recommend to use `yamllint` and `yamlfmt` together.- repo: https://github.com/adrienverge/yamllint.git
rev: v1.21.0 # or higher tag
hooks:
- id: yamllint
args: [--format, parsable, --strict]- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.1 # or other specific tag
hooks:
- id: yamlfmt#### Override defaults
Add to `.pre-commit-config.yaml` in your git repo:
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.1 # or other specific tag
hooks:
- id: yamlfmt
args: [--mapping, '2', --sequence, '2', --offset, '0', --colons, --width, '150']### Invoke pre-commit
#### On every commit
If you want to invoke the checks as a git pre-commit hook, run:
# Run on every commit.
pre-commit install#### On demand
If you want to run the checks on-demand (outside of git hooks), run:
# Run on-demand.
pre-commit run --all-filesThe [test harness](TESTING.md) of this git repo uses this approach.
## Contributing
Please see [CONTRIBUTING.md](CONTRIBUTING.md).
## Testing
Please see [TESTING.md](TESTING.md).
## License
The code in this repo is licensed under the [MIT License](LICENSE).