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

valast: slice got turns to different output than non-slice #5

Open
fabstu opened this issue Jan 6, 2021 · 2 comments
Open

valast: slice got turns to different output than non-slice #5

fabstu opened this issue Jan 6, 2021 · 2 comments
Labels

Comments

@fabstu
Copy link

fabstu commented Jan 6, 2021

A small example:

A slice got wraps the want-struct on each comma,

	tests := []struct {
		name string
		want autogold.Value
	}{
		{name: "good", want: autogold.Want("good", []A{A{
			A: valast.Addr("abc").(*string),
			B: "def",
			C: valast.Addr(false).(*bool),
			D: valast.Addr(true).(*bool),
		}})},
	}

while a non-slice got does not wrap on every comma

	tests := []struct {
		name string
		want autogold.Value
	}{
		{name: "good", want: autogold.Want("good", A{
			A: valast.Addr("abc").(*string), B: "def", C: valast.Addr(false).(*bool),
			D: valast.Addr(true).(*bool),
		})},
	}

. I think it would be nice for non-slice wants to also wrap them on every comma. I know this is a small thing, so may not be worth it. It may also be more compact to keep it the current way. But I'd love an option to have it both the same output style - the slice-way.

I hope this is something you want input about. I thought I mention it before it is in wider use and more difficult to change. :-)

@emidoots
Copy link
Member

emidoots commented Jan 6, 2021

Thanks for filing this!

Definitely want consistency here, ultimately this output is produced by https://github.com/hexops/valast in the form of an AST, put onto a single giant line of code, and then passed to https://github.com/mvdan/gofumpt for formatting. But right now gofumpt doesn't yet support formatting very long lines (mvdan/gofumpt#70) so we use a hack to get things broken onto multiple lines: https://github.com/hexops/valast/blob/main/valast.go#L118-L120

I think once mvdan/gofumpt#70 lands in gofumpt this should be improved quite a lot.

@fabstu
Copy link
Author

fabstu commented Jan 6, 2021

I didn't expect for it to be this complicated. Probably a good idea to use libraries if possible, less work. Thank you!

@emidoots emidoots changed the title Slice got turns to different output than non-slice valast: slice got turns to different output than non-slice Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants