diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 0ec1468..641ffc5 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -31,6 +31,14 @@ language: system files: (\.rego|\.yml|\.yaml|\.json|\.ini|\.toml|\.conf|\.hcl|\.cue|\.edn|\.vcl|\.xml|\.jsonnet|Dockerfile)$ +- id: conftest-fmt + name: Conftest fmt + description: Run `conftest fmt` on staged Rego files + entry: conftest fmt + language: system + args: ['.'] + files: (\.rego)$ + - id: conftest-verify name: Conftest verify description: Run `conftest verify` on rego files diff --git a/README.md b/README.md index 15f8243..6112c23 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,11 @@ Since it doesn't make sense to only provide `opa test` with the files changed (a args: ['my/policies', 'my/other/policies/'] ``` +#### `conftest-fmt` +Runs `conftest fmt` on any Rego files in the repository. + +Note that any files changed by this hook will need to be re-added (`git add`) to be included in the commit. + #### `conftest-test` Runs `conftest test` on any configuration file format supported by conftest. @@ -57,3 +62,11 @@ Just like with `opa-test` you'll likely want to specify the location of your con #### `conftest-verify` If rego files are present in commit, runs `conftest verify` in git root directory. + +Just like with `conftest-test` you'll likely want to specify the location of your conftest policies, and possibly what type of files changed should trigger the hook: + +```yaml +- id: conftest-verify + args: ['--policy', 'conftest/policy'] + files: conftest/.*\.yaml$ +```