PageSourceSearch

https://www.openpolicyagent.org/assets/js/3b8dc19e.e76a448d.js

js openpolicyagent.org collected 2026-09-24 08:29:05 UTC 3,830 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkopa_website=self.webpackChunkopa_website||[]).push([[13178],{28453:(e,n,l)=>{l.d(n,{R:()=>o,x:()=>a});var r=l(96540);const t={},i=r.createContext(t);function o(e){const n=r.useContext(i);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:o(e.components),r.createElement(i.Provider,{value:n},e.children)}},72332:(e,n,l)=>{l.r(n),l.d(n,{assets:()=>s,contentTitle:()=>a,default:()=>d,frontMatter:()=>o,metadata:()=>r,toc:()=>u});const r=JSON.parse('{"id":"rules/style/trailing-default-rule","title":"trailing-default-rule","description":"Summary: Default rule should be declared first","source":"@site/projects/regal/rules/style/trailing-default-rule.md","sourceDirName":"rules/style","slug":"/rules/style/trailing-default-rule","permalink":"/projects/regal/rules/style/trailing-default-rule","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{},"sidebar":"autoSidebar","previous":{"title":"todo-comment","permalink":"/projects/regal/rules/style/todo-comment"},"next":{"title":"unconditional-assignment","permalink":"/projects/regal/rules/style/unconditional-assignment"}}');var t=l(74848),i=l(28453);const o={},a="trailing-default-rule",s={},u=[{value:"Rationale",id:"rationale",level:2},{value:"Configuration Options",id:"configuration-options",level:2},{value:"Related Resources",id:"related-resources",level:2}];function c(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,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.header,{children:(0,t.jsx)(n.h1,{id:"trailing-default-rule",children:"trailing-default-rule"})}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"Summary"}),": Default rule should be declared first"]}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"Category"}),": Style"]}),"\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.strong,{children:"Avoid"})}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rego",children:"package policy\n\nallow if {\n    # some conditions\n}\n\ndefault allow := false\n"})}),"\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.strong,{children:"Prefer"})}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-rego",children:"package policy\n\ndefault allow := false\n\nallow if {\n    # some conditions\n}\n"})}),"\n",(0,t.jsx)(n.h2,{id:"rationale",children:"Rationale"}),"\n",(0,t.jsx)(n.p,{children:"Presenting the default value of a rule (if one is used) before the conditional rule assignments is a common practice,\nand it's often easier to to reason about conditional assignments knowing there is a default fallback value in place.\nFor that reason, it's recommended to follow the convention and place the default rule declaration before rules\nconditionally assigning values."}),"\n",(0,t.jsx)(n.h2,{id:"configuration-options",children:"Configuration Options"}),"\n",(0,t.jsx)(n.p,{children:"This linter rule provides the following configuration options:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-yaml",children:'rules:\n  style:\n    trailing-default-rule:\n      # one of "error", "warning", "ignore"\n      level: error\n'})}),"\n",(0,t.jsx)(n.h2,{id:"related-resources",children:"Related Resources"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["GitHub: ",(0,t.jsx)(n.a,{href:"https://github.com/open-policy-agent/regal/blob/main/bundle/regal/rules/style/trailing-default-rule/trailing_default_rule.rego",children:"Source Code"})]}),"\n"]})]})}function d(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(c,{...e})}):c(e)}}}]);

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.