Documentation ¶
Overview ¶
Package fmtdiff implements a goimports client as well as a parser that parses the diff between an original file and formatted one. You can use it as a wrapper for golang.org/x/tools/imports.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileDiff ¶
type FileDiff struct { // File name. Name string // Contents of original file. Before []byte // Contents of formatted file. After []byte Hunks []*Hunk }
FileDiff represents a diff between an original file and a formatted one.
func Process ¶ added in v0.8.1
Process runs goimports and parses the diff between an original file and a formatted one.
Note that filename's directory influences which imports can be chosen, so it is important that filename be accurate. To process data “as if” it were in filename, pass the data as a non-nil src.
type Hunk ¶
type Hunk struct { // OrigStartLine is the starting line number in the original file. OrigStartLine int // OrigLines is the number of lines the hunk applies to in the original file. OrigLines int // NewStartLine is the starting line number in the new file. NewStartLine int // NewLines is the number of lines the hunk applies to in the new file. NewLines int // Body is lines prefixed with '-', '+', or ' '. // The number of lines of context to show is three. Body []byte }
Hunk represents a series of changes in a file's unified diff.
type Options ¶
type Options struct { // LocalPrefixes is a set of import path prefixes, which, if set, // instructs Process to sort the import paths with the given prefixes // into another group after 3rd-party packages. Empty list by default. LocalPrefixes []string // Accept fragment of a source file (no package statement). False by default. Fragment bool // Report all errors (not just the first 10 on different lines). False by default. AllErrors bool // Do not print comments. False by default. IgnoreComments bool // Use spaces for indent. False by default. SpaceIndent bool // 8 is populated if zero provided. TabWidth int // Disable the insertion and deletion of imports. False by default. FormatOnly bool }
Options makes it possible to fine-tune behavior.