Documentation ¶
Overview ¶
Command golines is a formatter that shortens long go code lines, in addition to the formatting fixes done by gofmt.
$ go get -u github.com/segmentio/golines
See the project README for more details:
https://github.com/segmentio/golines/blob/master/README.md
File bugs or feature requests at:
https://github.com/segmentio/golines/issues
Index ¶
- func CreateAnnotation(length int) string
- func CreateDot(node dst.Node, out io.Writer) error
- func FormatStructTags(fieldList *dst.FieldList)
- func HasAnnotation(node dst.Node) bool
- func HasAnnotationRecursive(node dst.Node) bool
- func HasMultiKeyTags(lines []string) bool
- func IsAnnotation(line string) bool
- func ParseAnnotation(line string) int
- func PrettyDiff(path string, contents []byte, results []byte) error
- func WalkGraph(root *GraphNode) (string, error)
- type GraphEdge
- type GraphNode
- type Shortener
- type ShortenerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateAnnotation ¶
CreateAnnotation generates the text of a comment that will annotate long lines.
func FormatStructTags ¶
FormatStructTags formats struct tags so that the keys within each block of fields are aligned. It's not technically a shortening (and it usually makes these tags longer), so it's being kept separate from the core shortening logic for now.
See the struct_tags fixture for examples.
func HasAnnotation ¶
HasAnnotation determines whether the given AST node has a line length annotation on it.
func HasAnnotationRecursive ¶
HasAnnotationRecursive determines whether the given node or one of its children has a golines annotation on it. It's currently implemented for function declarations, fields, call expressions, and selector expressions only.
func HasMultiKeyTags ¶
HasMultiKeyTags returns whether the given lines have a multikey struct line. It's used as an optimization step to avoid unnnecessary shortening rounds.
func IsAnnotation ¶
IsAnnotation determines whether the given line is an annotation created with CreateAnnotation.
func ParseAnnotation ¶
ParseAnnotation returns the line length encoded in a golines annotation. If none is found, it returns -1.
func PrettyDiff ¶
PrettyDiff prints colored, git-style diffs to the console. It uses an embedded Python script (above) to take advantage of Python's difflib package.
Types ¶
type GraphNode ¶
type GraphNode struct { Type string Value string Node dst.Node Edges []*GraphEdge // contains filtered or unexported fields }
GraphNode is a representation of a node in the AST graph.
func NodeToGraphNode ¶
type Shortener ¶
type Shortener struct {
// contains filtered or unexported fields
}
Shortener shortens a single go file according to a small set of user style preferences.
func NewShortener ¶
func NewShortener(config ShortenerConfig) *Shortener
NewShortener creates a new shortener instance from the provided config.
type ShortenerConfig ¶
type ShortenerConfig struct { MaxLen int // Max target width for each line TabLen int // Width of a tab character KeepAnnotations bool // Whether to keep annotations in final result (for debugging only) ShortenComments bool // Whether to shorten comments ReformatTags bool // Whether to reformat struct tags in addition to shortening long lines IgnoreGenerated bool // Whether to ignore generated files DotFile string // Path to write dot-formatted output to (for debugging only) ChainSplitDots bool // Whether to split chain methods by putting dots at ends of lines // Formatter that will be run before and after main shortening process. If empty, // defaults to goimports (if found), otherwise gofmt. BaseFormatterCmd string }
ShortenerConfig stores the configuration options exposed by a Shortener instance.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package fixtures contains made-up go files used for testing golines under various conditions.
|
Package fixtures contains made-up go files used for testing golines under various conditions. |
Command generate is used to generate code that creates dot files from golang ASTs.
|
Command generate is used to generate code that creates dot files from golang ASTs. |