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 generates want for which some linters show a warning #6

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

Comments

@fabstu
Copy link

fabstu commented Jan 6, 2021

See this example:

	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),
		}})},
	}

[]A{A{ could be rewritten as []A{{. I'm not sure whether it s a linter or some other tool but the second A being there shows up as a warning in my code. It would be awesome if that could be avoided. Else I'd have to remote the A on every want-change, because it gets readded there again.

Another option would be to ignore this, but it would be nice if avoiding to write the A would be possible. :-)

The warning:

redundant type from array, slice, or map composite literalsimplifycompositelit
@slimsag
Copy link
Member

slimsag commented Jan 6, 2021

Thanks for filing this! I'll see if I can fix this soon (maybe around the weekend).

I agree it should be written as []A{{ here, it shouldn't be too hard to get valast to start emitting this style (we already do something similar for e.g. type unqualification in struct fields where a type is not needed.)

@fabstu
Copy link
Author

fabstu commented Jan 6, 2021

I don't know whether this is more about gofumpt or about valast. I found https://github.com/mvdan/gofumpt/blob/5bfeb2e70dd63f342c452468cca2ee21e180f91c/simplify.go#L105 which comes from cmd/gofmt. I thought the comment there hints that it should be adressed, but I'm uncertain. Thank you!

@slimsag slimsag changed the title Slice got generates want for which some linters show a warning valast: slice got generates want for which some linters show a warning Dec 20, 2022
@slimsag slimsag added the valast label 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