Skip to content
gofmt, the way it should be pronounced
Branch: master
Clone or download
Latest commit 4bef639 Apr 16, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gofumports add a drop-in replacement for goimports Apr 9, 2019
internal Don't add whitespace to sys/sysnb syscall function wrapper comments Apr 16, 2019
testdata/scripts
LICENSE
LICENSE.google separate the license files Apr 4, 2019
README.md Update README.md Apr 16, 2019
doc.go import source from cmd/gofmt Mar 30, 2019
go.mod add a drop-in replacement for goimports Apr 9, 2019
go.sum add a drop-in replacement for goimports Apr 9, 2019
gofmt.go separate gofumpt code into an importable package Apr 9, 2019
internal.go import source from cmd/gofmt Mar 30, 2019
main_test.go add a drop-in replacement for goimports Apr 9, 2019
rewrite.go import source from cmd/gofmt Mar 30, 2019
simplify.go import source from cmd/gofmt Mar 30, 2019

README.md

gofumpt

gofmt, the way it should be pronounced.

cd $(mktemp -d); go mod init tmp; go get mvdan.cc/gofumpt

Enforce a stricter format than gofmt, while being backwards compatible. That is, gofumpt is happy with a subset of the formats that gofmt is happy with.

The tool is a modified fork of gofmt, so it can be used as a drop-in replacement. Running gofmt after gofumpt should be a no-op.

A drop-in replacement for goimports is also available:

cd $(mktemp -d); go mod init tmp; go get mvdan.cc/gofumpt/gofumports

Features

No empty lines at the beginning or end of a function

example
func foo() {
	println("bar")

}
func foo() {
	println("bar")
}

No empty lines around a lone statement (or comment) in a block

example
if err != nil {

	return err
}
if err != nil {
	return err
}

Composite literals with elements in separate lines must also separate both braces

example
var ints = []int{1, 2,
	3, 4}
var ints = []int{
	1, 2,
	3, 4,
}

Short case clauses should take a single line

example
switch c {
case 'a', 'b',
	'c', 'd':
}
switch c {
case 'a', 'b', 'c', 'd':
}

Multiline top-level declarations must be separated by empty lines

example
func foo() {
	println("multiline foo")
}
func bar() {
	println("multiline bar")
}
func foo() {
	println("multiline foo")
}

func bar() {
	println("multiline bar")
}

A single declaration spec must not be grouped with parentheses

example
import (
	"single"
)

var (
	foo = "bar"
)
import "single"

var foo = "bar"

Comments which aren't Go directives should start with a whitespace

example
//go:noinline

//Foo is awesome.
func Foo() {}
//go:noinline

// Foo is awesome.
func Foo() {}

Installation

In order to use the tool with VS Code refer to this issue.

License

Note that much of the code is copied from Go's gofmt and goimports commands. You can tell which files originate from the Go repository from their copyright headers. Their license file is LICENSE.google.

gofumpt's original source files are also under the 3-clause BSD license, with the separate file LICENSE.

You can’t perform that action at this time.