layout

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package layout puts every element of a composite literal, every field of a struct type and every statement of a function literal on its own line.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equivalent

func Equivalent(src, out []byte) error

Equivalent reports how out differs from src beyond layout.

Types

type Correspondence

type Correspondence struct {
	// contains filtered or unexported fields
}

Correspondence maps code in a source file to the same code in a layout-only rewrite of it.

func NewCorrespondence

func NewCorrespondence(src, out []byte) (Correspondence, error)

NewCorrespondence pairs the tokens of src with those of out, which must be src with only its layout changed.

func (Correspondence) Span

func (c Correspondence) Span(start, end int) (int, int, error)

Span returns the byte offsets in the rewrite of the code between offsets start and end of the source, which must begin and end on a token, and refuses a span that a comment moves into or out of.

type Finding

type Finding struct {
	Kind Kind
	Node ast.Node
}

Finding is an inlined construct the rules cover.

type Kind

type Kind string

Kind is a construct the rules unfold.

const (
	CompositeLiteral Kind = "composite literal"
	StructType       Kind = "struct type"
	FunctionLiteral  Kind = "function literal"
)

The constructs the rules unfold.

func (Kind) ElementName

func (k Kind) ElementName() string

ElementName is what a construct of this kind holds, one per line.

type Rules

type Rules struct {
	CompositeLiterals bool
	StructTypes       bool
	FunctionLiterals  bool
	MinElements       int
}

Rules says which constructs are unfolded: MinElements counts elements, fields or statements.

func DefaultRules

func DefaultRules() Rules

DefaultRules unfolds every non-empty composite literal, struct type and function literal.

func (Rules) Findings

func (r Rules) Findings(fset *token.FileSet, file *ast.File) ([]Finding, error)

Findings returns the inlined constructs of file, in source order; fset holds file, parsed with its comments.

func (Rules) Unfold

func (r Rules) Unfold(src []byte) ([]byte, error)

Unfold returns src with every construct the rules cover spread one element, field or statement per line, formatted as gofmt does.

Jump to

Keyboard shortcuts

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