goreturns
goreturns copied to clipboard
Incorrect rewrite of bare return at end of block when comment follows
Here is a diff example of bare return rewrite when using goreturns -b -i -l -w .
:
if err != nil {
- return
+ return output,
+
+ // Processing output
+ err
}
- // Processing output
if updateCache {
expected result:
if err != nil {
- return
+ return output, err
}
// Processing output
if updateCache {
It is interesting that the rewrite escapes the {...}
block.
Heh, just came across this myself.
Preserving the comment structure is hard... https://github.com/golang/go/issues/18593
Edit:
and another useful reference, seems it is being considered ongoing: https://github.com/golang/go/issues/20744
Someone made another package representing the comments in another way which looks useful: https://github.com/dave/dst
Hey there! Author of dst
here... It should fix this problem. If you give it a go, let me know how it works...