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

proposal: fmt verb for indented Go-syntax representation of the value #27417

Closed
icholy opened this issue Aug 31, 2018 · 1 comment
Closed

proposal: fmt verb for indented Go-syntax representation of the value #27417

icholy opened this issue Aug 31, 2018 · 1 comment

Comments

@icholy
Copy link

icholy commented Aug 31, 2018

Currently, the %#v formatting verb places everything on one line. It would be useful for debugging to add a variation that outputs an indented version of the Go-Syntax representation.

type Foo struct {
	Bar Bar
	Baz string
}

type Bar struct {
	A string
	B int
}

var foo = Foo{
	Bar: Bar{
		A: "test",
		B: 42,
	},
	Baz: "Hello World",
}
// Go-Syntax representation
fmt.Printf("%#v\n", foo)

// Output
main.Foo{Bar:main.Bar{A:"test", B:42}, Baz:"Hello World"}

// Indented Go-Syntax representation
fmt.Printf("%##v\n", foo)

// Output
main.Foo{
	Bar: main.Bar{
		A: "test",
		B: 42,
	},
	Baz: "Hello World",
}

https://github.com/sanity-io/litter

@FiloSottile FiloSottile changed the title fmt: Go 2 verb for indented Go-syntax representation of the value proposal: fmt verb for indented Go-syntax representation of the value Aug 31, 2018
@gopherbot gopherbot added this to the Proposal milestone Aug 31, 2018
@martisch
Copy link
Contributor

A feature like this in fmt has been proposed and rejected previously in #23026. The complexity of multi line indentation of go syntax seems best served by another package outside of fmt instead of making fmt more complex.

If you have additional arguments that you think would change the conclusion from #23026, feel free to reopen this issue with additional context why fmt should contain this feature and external packages like https://godoc.org/github.com/kr/pretty or https://github.com/sanity-io/litter are not adequate to full fill the debugging use case.

Please also see https://golang.org/doc/faq#x_in_std for a general note why most new code not directly needed by compiler, runtime or features for existing packages that are not used heavily should better life outside the standard library.

@golang golang locked and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants