Back to Opa

Pre-Commit Hooks

docs/projects/regal/pre-commit-hooks.md

1.18.02.5 KB
Original Source
<head> <title>Pre-Commit Hooks | Regal</title> </head>

Pre-Commit Hooks

Pre-Commit is a framework for managing and maintaining multi-language pre-commit hooks. This allows running Regal automatically whenever (and as the name implied before) a Rego file is about to be committed.

To use Regal with pre-commit, add this to your .pre-commit-config.yaml

yaml
- repo: https://github.com/open-policy-agent/regal
  rev: v0.7.0 # Use the ref you want to point at
  hooks:
    - id: regal-lint
  # -   id: ...

Hooks Available

regal-lint

Runs Regal against all staged .rego files, aborting the commit if any fail.

  • requires the go build chain is installed and available on $PATH
  • will build and install the tagged version of Regal in an isolated GOPATH
  • ensures compatibility between versions

regal-lint-use-path

Runs Regal against all staged .rego files, aborting the commit if any fail.

  • requires the regal package is already installed and available on $PATH.

regal-download

Runs Regal against all staged .rego files, aborting the commit if any fail.

  • Downloads the latest regal binary from GitHub.

regal-fix

Runs regal fix against all staged .rego files, applying any auto-fixable rule violations in place. Use this alongside regal-lint when you want the hook to repair style-level issues automatically rather than asking the contributor to re-run regal fix themselves.

  • requires the go build chain is installed and available on $PATH
  • will build and install the tagged version of Regal in an isolated GOPATH
  • ensures compatibility between versions

regal-fix-use-path

Same as regal-fix, but uses the regal binary already on $PATH.

  • requires the regal package is already installed and available on $PATH.

regal-fix-download

Same as regal-fix, but downloads the latest regal binary from GitHub instead of building or relying on $PATH.

  • Downloads the latest regal binary from GitHub.