PageSourceSearch

https://www.openpolicyagent.org/assets/js/f55b63a3.ab7b62d8.js

js openpolicyagent.org collected 2026-09-24 08:31:49 UTC 4,481 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkopa_website=self.webpackChunkopa_website||[]).push([[36028],{13853:(e,n,o)=>{o.r(n),o.d(n,{assets:()=>a,contentTitle:()=>l,default:()=>u,frontMatter:()=>t,metadata:()=>r,toc:()=>c});const r=JSON.parse('{"id":"rules/custom/chained-rule-body","title":"chained-rule-body","description":"Summary: Avoid chaining rule bodies","source":"@site/projects/regal/rules/custom/chained-rule-body.md","sourceDirName":"rules/custom","slug":"/rules/custom/chained-rule-body","permalink":"/projects/regal/rules/custom/chained-rule-body","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{},"sidebar":"autoSidebar","previous":{"title":"Custom","permalink":"/projects/regal/rules/custom/"},"next":{"title":"disallow-rego-v1","permalink":"/projects/regal/rules/custom/disallow-rego-v1"}}');var s=o(74848),i=o(28453);const t={},l="chained-rule-body",a={},c=[{value:"Rationale",id:"rationale",level:2},{value:"Exceptions",id:"exceptions",level:2},{value:"Configuration Options",id:"configuration-options",level:2},{value:"Related Resources",id:"related-resources",level:2}];function d(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",header:"header",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.header,{children:(0,s.jsx)(n.h1,{id:"chained-rule-body",children:"chained-rule-body"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"Summary"}),": Avoid chaining rule bodies"]}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"Category"}),": Custom"]}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Avoid"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-rego",children:"package policy\n\nhas_x_or_y {\n    input.x\n} {\n    input.y\n}\n"})}),"\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"Prefer"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-rego",children:"package policy\n\nhas_x_or_y {\n    input.x\n}\n\nhas_x_or_y {\n    input.y\n}\n"})}),"\n",(0,s.jsx)(n.h2,{id:"rationale",children:"Rationale"}),"\n",(0,s.jsx)(n.p,{children:"If the head of the rule is same, it's possible to chain multiple rule bodies together to obtain the same result. This\nform was more common in the past, but is no longer recommended as it is arguably less readable, and less likely to be\nunderstood by people new to Rego."}),"\n",(0,s.jsx)(n.h2,{id:"exceptions",children:"Exceptions"}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"opa fmt"}),' command will automatically "unchain" chained rule bodies, so if you have enabled the ',(0,s.jsx)(n.a,{href:"https://www.openpolicyagent.org/projects/regal/rules/style/opa-fmt",children:"opa-fmt"}),"\nrule (as it is by default), there's no point in enabling this rule."]}),"\n",(0,s.jsx)(n.h2,{id:"configuration-options",children:"Configuration Options"}),"\n",(0,s.jsx)(n.p,{children:"This linter rule provides the following configuration options:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-yaml",children:'rules:\n  custom:\n    chained-rule-body:\n      # note that all rules in the "custom" category are disabled by default\n      # (i.e. level "ignore") as some configuration needs to be provided by\n      # the user (i.e. you!) in order for them to be useful.\n      #\n      # one of "error", "warning", "ignore"\n      level: error\n'})}),"\n",(0,s.jsx)(n.h2,{id:"related-resources",children:"Related Resources"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["OPA Docs: ",(0,s.jsx)(n.a,{href:"https://www.openpolicyagent.org/docs/policy-language/#incremental-definitions",children:"Incremental Definitions"})]}),"\n",(0,s.jsxs)(n.li,{children:["GitHub: ",(0,s.jsx)(n.a,{href:"https://github.com/open-policy-agent/regal/blob/main/bundle/regal/rules/custom/chained-rule-body/chained_rule_body.rego",children:"Source Code"})]}),"\n"]})]})}function u(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},28453:(e,n,o)=>{o.d(n,{R:()=>t,x:()=>l});var r=o(96540);const s={},i=r.createContext(s);function t(e){const n=r.useContext(i);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:t(e.components),r.createElement(i.Provider,{value:n},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.