1"use strict";(self.webpackChunkopa_website=self.webpackChunkopa_website||[]).push([[20698],{20822:(e,i,l)=>{l.r(i),l.d(i,{assets:()=>t,contentTitle:()=>r,default:()=>h,frontMatter:()=>a,metadata:()=>o,toc:()=>d});const o=JSON.parse('{"id":"pre-commit-hooks","title":"pre-commit-hooks","description":"Pre-Commit Hooks | Regal","source":"@site/projects/regal/pre-commit-hooks.md","sourceDirName":".","slug":"/pre-commit-hooks","permalink":"/projects/regal/pre-commit-hooks","draft":false,"unlisted":false,"tags":[],"version":"current","sidebarPosition":6,"frontMatter":{"sidebar_position":6,"sidebar_label":"Pre-Commit Hooks"},"sidebar":"autoSidebar","previous":{"title":"Roast","permalink":"/projects/regal/custom-rules/roast"},"next":{"title":"Editor Support","permalink":"/projects/regal/editor-support"}}');var n=l(74848),s=l(28453);const a={sidebar_position:6,sidebar_label:"Pre-Commit Hooks"},r="Pre-Commit Hooks",t={},d=[{value:"Hooks Available",id:"hooks-available",level:2},{value:"<code>regal-lint</code>",id:"regal-lint",level:3},{value:"<code>regal-lint-use-path</code>",id:"regal-lint-use-path",level:3},{value:"<code>regal-download</code>",id:"regal-download",level:3},{value:"<code>regal-fix</code>",id:"regal-fix",level:3},{value:"<code>regal-fix-use-path</code>",id:"regal-fix-use-path",level:3},{value:"<code>regal-fix-download</code>",id:"regal-fix-download",level:3}];function c(e){const i={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",img:"img",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.R)(),...e.components},{Head:l}=i;return l||function(e,i){throw new Error("Expected "+(i?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}("Head",!0),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(l,{children:(0,n.jsx)("title",{children:"Pre-Commit Hooks | Regal"})}),"\n",(0,n.jsx)(i.header,{children:(0,n.jsx)(i.h1,{id:"pre-commit-hooks",children:"Pre-Commit Hooks"})}),"\n",(0,n.jsxs)(i.p,{children:[(0,n.jsx)(i.a,{href:"https://pre-commit.com",children:"Pre-Commit"})," is a framework for managing and maintaining multi-language pre-commit hooks.\nThis allows running Regal automatically whenever (and as the name implied before) a Rego file is about to be committed."]}),"\n",(0,n.jsxs)(i.p,{children:["To use Regal with pre-commit, add this to your ",(0,n.jsx)(i.code,{children:".pre-commit-config.yaml"})]}),"\n",(0,n.jsx)(i.pre,{children:(0,n.jsx)(i.code,{className:"language-yaml",children:"- repo: https://github.com/open-policy-agent/regal\n rev: v0.7.0 # Use the ref you want to point at\n hooks:\n - id: regal-lint\n # - id: ...\n"})}),"\n",(0,n.jsx)(i.h2,{id:"hooks-available",children:"Hooks Available"}),"\n",(0,n.jsx)(i.h3,{id:"regal-lint",children:(0,n.jsx)(i.code,{children:"regal-lint"})}),"\n",(0,n.jsx)(i.p,{children:(0,n.jsx)(i.img,{src:"https://img.shields.io/badge/hook-pre--commit-informational?logo=git",alt:"commit-msg hook"})}),"\n",(0,n.jsxs)(i.p,{children:["Runs Regal against all staged ",(0,n.jsx)(i.code,{children:".rego"})," files, aborting the commit if any fail."]}),"\n",(0,n.jsxs)(i.ul,{children:["\n",(0,n.jsxs)(i.li,{children:["requires the ",(0,n.jsx)(i.code,{children:"go"})," build chain is installed and available on ",(0,n.jsx)(i.code,{children:"$PATH"})]}),"\n",(0,n.jsxs)(i.li,{children:["will build and install the tagged version of Regal in an isolated ",(0,n.jsx)(i.code,{children:"GOPATH"})]}),"\n",(0,n.jsx)(i.li,{children:"ensures compatibility between versions"}),"\n"]}),"\n",(0,n.jsx)(i.h3,{id:"regal-lint-use-path",children:(0,n.jsx)(i.code,{children:"regal-lint-use-path"})}),"\n",(0,n.jsx)(i.p,{children:(0,n.jsx)(i.img,{src:"https://img.shields.io/badge/hook-pre--commit-informational?logo=git",alt:"commit-msg hook"})}),"\n",(0,n.jsxs)(i.p,{children:["Runs Regal against all staged ",(0,n.jsx)(i.code,{children:".rego"})," files, aborting the commit if any fail."]}),"\n",(0,n.jsxs)(i.ul,{children:["\n",(0,n.jsxs)(i.li,{children:["requires the ",(0,n.jsx)(i.code,{children:"regal"})," package is already installed and available on ",(0,n.jsx)(i.code,{children:"$PATH"}),"."]}),"\n"]}),"\n",(0,n.jsx)(i.h3,{id:"regal-download",children:(0,n.jsx)(i.co
1de,{children:"regal-download"})}),"\n",(0,n.jsx)(i.p,{children:(0,n.jsx)(i.img,{src:"https://img.shields.io/badge/hook-pre--commit-informational?logo=git",alt:"commit-msg hook"})}),"\n",(0,n.jsxs)(i.p,{children:["Runs Regal against all staged ",(0,n.jsx)(i.code,{children:".rego"})," files, aborting the commit if any fail."]}),"\n",(0,n.jsxs)(i.ul,{children:["\n",(0,n.jsxs)(i.li,{children:["Downloads the latest ",(0,n.jsx)(i.code,{children:"regal"})," binary from Github."]}),"\n"]}),"\n",(0,n.jsx)(i.h3,{id:"regal-fix",children:(0,n.jsx)(i.code,{children:"regal-fix"})}),"\n",(0,n.jsx)(i.p,{children:(0,n.jsx)(i.img,{src:"https://img.shields.io/badge/hook-pre--commit-informational?logo=git",alt:"commit-msg hook"})}),"\n",(0,n.jsxs)(i.p,{children:["Runs ",(0,n.jsx)(i.code,{children:"regal fix"})," against all staged ",(0,n.jsx)(i.code,{children:".rego"})," files, applying any\nauto-fixable rule violations in place. Use this alongside ",(0,n.jsx)(i.code,{children:"regal-lint"})," when you\nwant the hook to repair style-level issues automatically rather than asking the\ncontributor to re-run ",(0,n.jsx)(i.code,{children:"regal fix"})," themselves."]}),"\n",(0,n.jsxs)(i.ul,{children:["\n",(0,n.jsxs)(i.li,{children:["requires the ",(0,n.jsx)(i.code,{children:"go"})," build chain is installed and available on ",(0,n.jsx)(i.code,{children:"$PATH"})]}),"\n",(0,n.jsxs)(i.li,{children:["will build and install the tagged version of Regal in an isolated ",(0,n.jsx)(i.code,{children:"GOPATH"})]}),"\n",(0,n.jsx)(i.li,{children:"ensures compatibility between versions"}),"\n"]}),"\n",(0,n.jsx)(i.h3,{id:"regal-fix-use-path",children:(0,n.jsx)(i.code,{children:"regal-fix-use-path"})}),"\n",(0,n.jsx)(i.p,{children:(0,n.jsx)(i.img,{src:"https://img.shields.io/badge/hook-pre--commit-informational?logo=git",alt:"commit-msg hook"})}),"\n",(0,n.jsxs)(i.p,{children:["Same as ",(0,n.jsx)(i.code,{children:"regal-fix"}),", but uses the ",(0,n.jsx)(i.code,{children:"regal"})," binary already on ",(0,n.jsx)(i.code,{children:"$PATH"}),"."]}),"\n",(0,n.jsxs)(i.ul,{children:["\n",(0,n.jsxs)(i.li,{children:["requires the ",(0,n.jsx)(i.code,{children:"regal"})," package is already installed and available on ",(0,n.jsx)(i.code,{children:"$PATH"}),"."]}),"\n"]}),"\n",(0,n.jsx)(i.h3,{id:"regal-fix-download",children:(0,n.jsx)(i.code,{children:"regal-fix-download"})}),"\n",(0,n.jsx)(i.p,{children:(0,n.jsx)(i.img,{src:"https://img.shields.io/badge/hook-pre--commit-informational?logo=git",alt:"commit-msg hook"})}),"\n",(0,n.jsxs)(i.p,{children:["Same as ",(0,n.jsx)(i.code,{children:"regal-fix"}),", but downloads the latest ",(0,n.jsx)(i.code,{children:"regal"})," binary from GitHub instead of building or relying on ",(0,n.jsx)(i.code,{children:"$PATH"}),"."]}),"\n",(0,n.jsxs)(i.ul,{children:["\n",(0,n.jsxs)(i.li,{children:["Downloads the latest ",(0,n.jsx)(i.code,{children:"regal"})," binary from Github."]}),"\n"]})]})}function h(e={}){const{wrapper:i}={...(0,s.R)(),...e.components};return i?(0,n.jsx)(i,{...e,children:(0,n.jsx)(c,{...e})}):c(e)}},28453:(e,i,l)=>{l.d(i,{R:()=>a,x:()=>r});var o=l(96540);const n={},s=o.createContext(n);function a(e){const i=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(i):{...i,...e}}),[i,e])}function r(e){let i;return i=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:a(e.components),o.createElement(s.Provider,{value:i},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.