gofumpt
gofumpt copied to clipboard
Unexpected splitting of function arguments
Given the following code (constraints
, slices
, and maps
are the golang.org/x/exp
packages of the same name):
func SortedKeys[K interface {
comparable
constraints.Ordered
}, V any](m map[K]V) []K {
keys := maps.Keys(m)
slices.Sort(keys)
return keys
}
gofumpt@latest
(900c61a4cb83bedde751dd2aedf2fc1c73de5e40) reformats this to:
func SortedKeys[K interface {
comparable
constraints.Ordered
}, V any](m map[K]V,
) []K {
keys := maps.Keys(m)
slices.Sort(keys)
return keys
}
which has this diff:
--- a 2022-06-19 16:24:24.237245879 +0000
+++ b 2022-06-19 16:25:48.403318940 +0000
@@ -1,7 +1,8 @@
func SortedKeys[K interface {
comparable
constraints.Ordered
-}, V any](m map[K]V) []K {
+}, V any](m map[K]V,
+) []K {
keys := maps.Keys(m)
slices.Sort(keys)
return keys
I did not expect the function arguments to be split over two lines. I'm only starting to learn generics, so this might however be idiomatic. Please do close this issue if it is invalid.
This rule was tested before the introduction of generics, so my best guess is that this is unintended :) Have you tried the latest master version as well, to see if the same problem occurs?
cc @Oiyoo
Yes, I've tested with the latest master (900c61a4cb83bedde751dd2aedf2fc1c73de5e40) and the same problem occurs.
I can confirm that this is an issue on v0.3.2-0.20220627183521-8dda8068d9f3
, which is the latest commit in master
.
Here is a possible another case:
package fact
func
Factorial(x int) int {
return x * Factorial(x - 1,
)
}
converted to:
package fact
func Factorial(x int,
) int {
return x * Factorial(x-1)
}