dockerfmt

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatComments

func FormatComments(lines []string) string

func FormatFileLines

func FormatFileLines(fileLines io.Reader, c *Config) ([]byte, error)

func FormatNode

func FormatNode(ast *ExtendedNode, c *Config) (string, bool)

func FormatOnBuild

func FormatOnBuild(n *ExtendedNode, c *Config) string

func GetFileLines

func GetFileLines(fileName string) ([]string, error)

func IndentFollowingLines

func IndentFollowingLines(lines string, indentSize uint) string

func Marshal

func Marshal(i interface{}) ([]byte, error)

Marshal is a UTF-8 friendly marshaler. Go's json.Marshal is not UTF-8 friendly because it replaces the valid UTF-8 and JSON characters "&". "<", ">" with the "slash u" unicode escaped forms (e.g. \u0026). It preemptively escapes for HTML friendliness. Where text may include any of these characters, json.Marshal should not be used. Playground of Go breaking a title: https://play.golang.org/p/o2hiX0c62oN Source: https://stackoverflow.com/a/69502657/5684541

func StripWhitespace

func StripWhitespace(lines string, rightOnly bool) string

Types

type Config

type Config struct {
	IndentSize      uint
	TrailingNewline bool
	SpaceRedirects  bool
}

type ExtendedNode

type ExtendedNode struct {
	*parser.Node
	Children          []*ExtendedNode
	Next              *ExtendedNode
	OriginalMultiline string
}

func BuildExtendedNode

func BuildExtendedNode(n *parser.Node, fileLines []string) *ExtendedNode

type Formatter

type Formatter struct {
}

Formatter implements the format.Provider interface for Dockerfiles.

func NewFormatter

func NewFormatter() *Formatter

NewFormatter creates a new Dockerfile formatter.

func (*Formatter) Format

func (f *Formatter) Format(ctx context.Context, cfg format.Configuration, read io.Reader) (io.Reader, error)

Format parses and formats Dockerfile code.

func (*Formatter) Targets

func (f *Formatter) Targets() []string

Targets returns the file patterns this formatter handles.

type ParseState

type ParseState struct {
	CurrentLine int
	Output      string
	// Needed to pull in comments
	AllOriginalLines []string
	Config           *Config
}

Jump to

Keyboard shortcuts

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