jsonnetfmt
is a code-formatter that comes with Jsonnet.
Pre-Commit is a library for creating and applying Git pre-commit hooks easily.
Together, you can automatically run jsonnetfmt
before any commit, automatically.
- Get pre-commit:
pip install pre-commit
- Create a
.pre-commit.config.yaml
file in the root of your repository:
---
repos:
- repo: https://github.com/waisbrot/pre-commit-jsonnet.git
rev: v1.0
hooks:
- id: jsonnetfmt
- Install the hooks:
pre-commit install
- Commit code including a .jsonnet or .libsonnet file and it will run through
jsonnetfmt
- If the file was modified,
pre-commit
will abort the commit so you can check the changes. (git diff
will show you changes between what you staged and whatjsonnetfmt
did.) Stage the modifications and commit again.