package format
import "github.com/open-policy-agent/opa/format"
Package format implements formatting of Rego source files.
Index ¶
- func ArityFormatMismatchError(operands []*ast.Term, operator string, loc *ast.Location, f *types.Function) *ast.Error
- func Ast(x interface{}) ([]byte, error)
- func AstWithOpts(x interface{}, opts Opts) ([]byte, error)
- func MustAst(x interface{}) []byte
- func Source(filename string, src []byte) ([]byte, error)
- func SourceWithOpts(filename string, src []byte, opts Opts) ([]byte, error)
- type ArityFormatErrDetail
- type Opts
Functions ¶
func ArityFormatMismatchError ¶
func ArityFormatMismatchError(operands []*ast.Term, operator string, loc *ast.Location, f *types.Function) *ast.Error
arityMismatchError but for `fmt` checks since the compiler has not run yet.
func Ast ¶
Ast formats a Rego AST element. If the passed value is not a valid AST element, Ast returns nil and an error. If AST nodes are missing locations an arbitrary location will be used.
func AstWithOpts ¶
func MustAst ¶
func MustAst(x interface{}) []byte
MustAst is a helper function to format a Rego AST element. If any errors occurs this function will panic. This is mostly used for test
func Source ¶
Source formats a Rego source file. The bytes provided must describe a complete Rego module. If they don't, Source will return an error resulting from the attempt to parse the bytes.
func SourceWithOpts ¶
Types ¶
type ArityFormatErrDetail ¶
ArgErrDetail but for `fmt` checks since compiler has not run yet.
func (*ArityFormatErrDetail) Lines ¶
func (d *ArityFormatErrDetail) Lines() []string
Lines returns the string representation of the detail.
type Opts ¶
type Opts struct { // IgnoreLocations instructs the formatter not to use the AST nodes' locations // into account when laying out the code: notably, when the input is the result // of partial evaluation, arguments maybe have been shuffled around, but still // carry along their original source locations. IgnoreLocations bool RegoV1 bool }
Opts lets you control the code formatting via `AstWithOpts()`.
Source Files ¶
- Version
- v0.59.0
- Published
- Nov 30, 2023
- Platform
- js/wasm
- Imports
- 9 packages
- Last checked
- 1 hour ago –
Tools for package owners.