format

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2025 License: Apache-2.0 Imports: 3 Imported by: 36

Documentation

Overview

Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended. For newer features and behaviours, such as defaulting to the Rego v1 syntax, use the corresponding components in the github.com/open-policy-agent/opa/v1 package instead. See https://www.openpolicyagent.org/docs/latest/v0-compatibility/ for more information.

Package format implements formatting of Rego source files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArityFormatMismatchError added in v0.51.0

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

func Ast(x interface{}) ([]byte, error)

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 added in v0.40.0

func AstWithOpts(x interface{}, opts Opts) ([]byte, error)

func MustAst added in v0.9.2

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 MustAstWithOpts added in v0.69.0

func MustAstWithOpts(x interface{}, opts Opts) []byte

MustAstWithOpts 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

func Source(filename string, src []byte) ([]byte, error)

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 added in v0.59.0

func SourceWithOpts(filename string, src []byte, opts Opts) ([]byte, error)

Types

type ArityFormatErrDetail added in v0.51.0

type ArityFormatErrDetail = v1.ArityFormatErrDetail

ArgErrDetail but for `fmt` checks since compiler has not run yet.

type Opts added in v0.40.0

type Opts = v1.Opts

Opts lets you control the code formatting via `AstWithOpts()`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL