Skip to content

Commit

Permalink
Feat: Format syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaigalos committed May 26, 2023
1 parent c33d013 commit d620e71
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -78,35 +82,39 @@ 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

#### On every commit

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.

Expand Down

0 comments on commit d620e71

Please sign in to comment.