package format

import "github.com/open-policy-agent/opa/format"

Package format implements formatting of Rego source files.

Index

Functions

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

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

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

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.

Types

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
}

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

Source Files

format.go

Version
v0.46.0
Published
Nov 3, 2022
Platform
js/wasm
Imports
6 packages
Last checked
36 minutes ago

Tools for package owners.