formatter

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 1 Imported by: 26

Documentation

Overview

Package formatter is what powers jsonnetfmt, a Jsonnet formatter. It works similar to most other code formatters. Basically said, it takes the contents of a file and returns them properly formatted. Behaviour can be customized using formatter.Options.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(filename string, input string, options Options) (string, error)

Format returns code that is equivalent to its input but better formatted according to the given options.

Types

type CommentStyle

type CommentStyle = formatter.CommentStyle

CommentStyle controls how the reformatter rewrites comments. Comments that look like a #! hashbang are always left alone.

const (
	// CommentStyleHash means #.
	CommentStyleHash CommentStyle = iota
	// CommentStyleSlash means //.
	CommentStyleSlash
	// CommentStyleLeave means comments are left as they are found.
	CommentStyleLeave
)

type Options

type Options = formatter.Options

Options is a set of parameters that control the reformatter's behaviour.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the recommended formatter behaviour.

type StringStyle

type StringStyle = formatter.StringStyle

StringStyle controls how the reformatter rewrites string literals. Strings that contain a ' or a " use the optimal syntax to avoid escaping those characters.

const (
	// StringStyleDouble means "this".
	StringStyleDouble StringStyle = iota
	// StringStyleSingle means 'this'.
	StringStyleSingle
	// StringStyleLeave means strings are left how they were found.
	StringStyleLeave
)

Jump to

Keyboard shortcuts

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