Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gofumpt instead of gofmt #4623

Merged
merged 5 commits into from
Oct 16, 2023
Merged

Use gofumpt instead of gofmt #4623

merged 5 commits into from
Oct 16, 2023

Conversation

MrAlias
Copy link
Contributor

@MrAlias MrAlias commented Oct 13, 2023

gofumpt is a stricter version of gofmt.

Notably:

No empty lines following an assignment operator

func foo() {
    foo :=
        "bar"
}
func foo() {
	foo := "bar"
}

No empty lines around function bodies

func foo() {

	println("bar")

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

Functions should separate ) { where the indentation helps readability

func foo(s string,
	i int) {
	println("bar")
}

// With an empty line it's slightly better, but still not great.
func bar(s string,
	i int) {

	println("bar")
}
func foo(s string,
	i int,
) {
	println("bar")
}

// With an empty line it's slightly better, but still not great.
func bar(s string,
	i int,
) {
	println("bar")
}

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

if err != nil {

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

No empty lines before a simple error check

foo, err := processFoo()

if err != nil {
	return err
}
foo, err := processFoo()
if err != nil {
	return err
}

Composite literals should use newlines consistently

// A newline before or after an element requires newlines for the opening and
// closing braces.
var ints = []int{1, 2,
	3, 4}

// A newline between consecutive elements requires a newline between all
// elements.
var matrix = [][]int{
	{1},
	{2}, {
		3,
	},
}
var ints = []int{
	1, 2,
	3, 4,
}

var matrix = [][]int{
	{1},
	{2},
	{
		3,
	},
}

Empty field lists should use a single line

var V interface {
} = 3

type T struct {
}

func F(
)
var V interface{} = 3

type T struct{}

func F()

std imports must be in a separate group at the top

import (
	"foo.com/bar"

	"io"

	"io/ioutil"
)
import (
	"io"
	"io/ioutil"

	"foo.com/bar"
)

Short case clauses should take a single line

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

Multiline top-level declarations must be separated by empty lines

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

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

Single var declarations should not be grouped with parentheses

var (
	foo = "bar"
)
var foo = "bar"

Contiguous top-level declarations should be grouped together

var nicer = "x"
var with = "y"
var alignment = "z"
var (
	nicer     = "x"
	with      = "y"
	alignment = "z"
)

Simple var-declaration statements should use short assignments

var s = "somestring"
s := "somestring"

The -s code simplification flag is enabled by default

var _ = [][]int{[]int{1}}
var _ = [][]int{{1}}

Octal integer literals should use the 0o prefix on modules using Go 1.13 and later

const perm = 0755
const perm = 0o755

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

//go:noinline

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

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

Composite literals should not have leading or trailing empty lines

var _ = []string{

	"foo",

}

var _ = map[string]string{

	"foo": "bar",

}
var _ = []string{
	"foo",
}

var _ = map[string]string{
	"foo": "bar",
}

Field lists should not have leading or trailing empty lines

type Person interface {

	Name() string

	Age() int

}

type ZeroFields struct {

	// No fields are needed here.

}
type Person interface {
	Name() string

	Age() int
}

type ZeroFields struct {
	// No fields are needed here.
}

@MrAlias MrAlias added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Oct 13, 2023
Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love gofumpt and there is no need to convince me (I use it since v0.1.0) 😉

PS. I see that there is still some formatting missing, but the CI anyway will make sure that you will fix it.

@codecov
Copy link

codecov bot commented Oct 13, 2023

Codecov Report

Merging #4623 (f73d7c6) into main (c047088) will increase coverage by 0.0%.
Report is 1 commits behind head on main.
The diff coverage is 50.0%.

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #4623   +/-   ##
=====================================
  Coverage   81.3%   81.3%           
=====================================
  Files        222     222           
  Lines      17683   17682    -1     
=====================================
+ Hits       14390   14391    +1     
+ Misses      2993    2991    -2     
  Partials     300     300           
Files Coverage Δ
bridge/opentracing/bridge.go 63.7% <ø> (ø)
bridge/opentracing/internal/mock.go 67.0% <ø> (ø)
bridge/opentracing/wrapper.go 100.0% <ø> (ø)
...otlpmetric/otlpmetricgrpc/internal/otest/client.go 97.1% <ø> (ø)
...otlpmetric/otlpmetrichttp/internal/otest/client.go 97.1% <ø> (ø)
exporters/otlp/otlptrace/exporter.go 66.6% <100.0%> (ø)
exporters/stdout/stdoutmetric/exporter.go 90.1% <ø> (ø)
exporters/zipkin/internal/matchers/expectation.go 0.0% <ø> (ø)
internal/global/instruments.go 60.8% <ø> (ø)
internal/matchers/expectation.go 0.0% <ø> (ø)
... and 18 more

@MrAlias

This comment was marked as resolved.

@MrAlias

This comment was marked as resolved.

@MrAlias

This comment was marked as resolved.

@MrAlias

This comment was marked as resolved.

@pellared

This comment was marked as resolved.

@pellared

This comment was marked as resolved.

@MrAlias MrAlias merged commit 5dff273 into open-telemetry:main Oct 16, 2023
@MrAlias MrAlias deleted the gofumpt branch October 16, 2023 17:02
@MrAlias MrAlias added this to the v1.20.0 milestone Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants