Skip to content

Commit d620e71

Browse files
committed
Feat: Format syntax
1 parent c33d013 commit d620e71

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ to do the heavy lifting and preserve comments within YAML files.
3131

3232
Add to `.pre-commit-config.yaml` in your git repo:
3333

34+
```yaml
3435
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
3536
rev: 0.2.1 # or other specific tag
3637
hooks:
3738
- id: yamlfmt
39+
```
3840
3941
:bulb: If a pre-commit hook changes a file,
4042
the hook fails with a warning that files were changed.
@@ -48,26 +50,28 @@ The default settings are:
4850
- `width`: None (use ruamel default)
4951

5052
Given this input:
51-
53+
```yaml
5254
foo:
5355
bar:
5456
- baz1
5557
- baz2
56-
58+
```
5759
The default settings result in this output:
5860

61+
```yaml
5962
---
6063
foo:
6164
bar:
6265
- baz1
6366
- baz2
64-
67+
```
6568

6669
#### Combine with `yamllint`
6770

6871
`yamlfmt` only works with valid YAML files, so
6972
I recommend to use `yamllint` and `yamlfmt` together.
7073

74+
```yaml
7175
- repo: https://github.com/adrienverge/yamllint.git
7276
rev: v1.21.0 # or higher tag
7377
hooks:
@@ -78,35 +82,39 @@ I recommend to use `yamllint` and `yamlfmt` together.
7882
rev: 0.2.1 # or other specific tag
7983
hooks:
8084
- id: yamlfmt
81-
85+
```
8286

8387
#### Override defaults
8488

8589
Add to `.pre-commit-config.yaml` in your git repo:
8690

91+
```yaml
8792
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
8893
rev: 0.2.1 # or other specific tag
8994
hooks:
9095
- id: yamlfmt
9196
args: [--mapping, '4', --sequence, '4', --offset, '2', --colons, --width, '150']
92-
97+
```
9398

9499
### Invoke pre-commit
95100

96101
#### On every commit
97102

98103
If you want to invoke the checks as a git pre-commit hook, run:
99104

100-
# Run on every commit.
101-
pre-commit install
102-
105+
```bash
106+
# Run on every commit.
107+
pre-commit install
108+
```
103109

104110
#### On demand
105111

106112
If you want to run the checks on-demand (outside of git hooks), run:
107113

108-
# Run on-demand.
109-
pre-commit run --all-files
114+
```bash
115+
# Run on-demand.
116+
pre-commit run --all-files
117+
```
110118

111119
The [test harness](TESTING.md) of this git repo uses this approach.
112120

0 commit comments

Comments
 (0)