format

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package format exposes gofumpt's formatting in an API similar to go/format. In general, the APIs are only guaranteed to work well when the input source is in canonical gofmt format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func File

func File(fset *token.FileSet, file *ast.File, opts Options)

File modifies a file and fset in place to follow gofumpt's format. The changes might include manipulating adding or removing newlines in fset, modifying the position of nodes, or modifying literal values.

func SortImports

func SortImports(localPrefix string, fset *token.FileSet, f *ast.File)

SortImports sorts runs of consecutive import lines in import blocks in f. It also removes duplicate imports when it is possible to do so without data loss.

func Source

func Source(src []byte, opts Options) ([]byte, error)

Source formats src in gofumpt's format, assuming that src holds a valid Go source file.

Types

type Options

type Options struct {
	// LangVersion corresponds to the Go language version a piece of code is
	// written in. The version is used to decide whether to apply formatting
	// rules which require new language features. When inside a Go module,
	// LangVersion should be:
	//
	//     go mod edit -json | jq -r '.Go'
	//
	// LangVersion is treated as a semantic version, which may start with a "v"
	// prefix. Like Go versions, it may also be incomplete; "1.14" is equivalent
	// to "1.14.0". When empty, it is equivalent to "v1", to not use language
	// features which could break programs.
	LangVersion string

	// ModulePath corresponds to the Go module path which contains the source
	// code being formatted. When inside a Go module, ModulePath should be:
	//
	//     go mod edit -json | jq -r '.Module.Path'
	//
	// ModulePath is used for formatting decisions like what import paths are
	// considered to be not part of the standard library. When empty, the source
	// is formatted as if it weren't inside a module.
	ModulePath string

	// ExtraRules enables extra formatting rules, such as grouping function
	// parameters with repeated types together.
	ExtraRules bool

	LocalPrefix string
}

Options is the set of formatting options which affect gofumpt.

Jump to

Keyboard shortcuts

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