format

package
v0.63.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 9 Imported by: 37

Documentation

Overview

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 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 struct {
	Have []string `json:"have"`
	Want []string `json:"want"`
}

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

func (*ArityFormatErrDetail) Lines added in v0.51.0

func (d *ArityFormatErrDetail) Lines() []string

Lines returns the string representation of the detail.

type Opts added in v0.40.0

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

	// RegoVersion is the version of Rego to format code for.
	RegoVersion ast.RegoVersion
}

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