From d620e711b4139dfc745067deec5e26c44957e410 Mon Sep 17 00:00:00 2001 From: Mihai Galos Date: Fri, 26 May 2023 19:51:59 +0200 Subject: [PATCH] Feat: Format syntax --- README.md | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c0954a1..9859c41 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,12 @@ to do the heavy lifting and preserve comments within YAML files. Add to `.pre-commit-config.yaml` in your git repo: +```yaml - 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. @@ -48,26 +50,28 @@ The default settings are: - `width`: None (use ruamel default) Given this input: - +```yaml foo: bar: - baz1 - baz2 - +``` The default settings result in this output: +```yaml --- foo: bar: - baz1 - baz2 - +``` #### Combine with `yamllint` `yamlfmt` only works with valid YAML files, so I recommend to use `yamllint` and `yamlfmt` together. +```yaml - repo: https://github.com/adrienverge/yamllint.git rev: v1.21.0 # or higher tag hooks: @@ -78,18 +82,19 @@ I recommend to use `yamllint` and `yamlfmt` together. rev: 0.2.1 # or other specific tag hooks: - id: yamlfmt - +``` #### Override defaults Add to `.pre-commit-config.yaml` in your git repo: +```yaml - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt rev: 0.2.1 # or other specific tag hooks: - id: yamlfmt args: [--mapping, '4', --sequence, '4', --offset, '2', --colons, --width, '150'] - +``` ### Invoke pre-commit @@ -97,16 +102,19 @@ Add to `.pre-commit-config.yaml` in your git repo: If you want to invoke the checks as a git pre-commit hook, run: - # Run on every commit. - pre-commit install - +```bash +# 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-files +```bash +# Run on-demand. +pre-commit run --all-files +``` The [test harness](TESTING.md) of this git repo uses this approach.