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

Incorrect rewrite of bare return at end of block when comment follows #57

Open
philoserf opened this issue Dec 7, 2018 · 2 comments
Open

Comments

@philoserf
Copy link

philoserf commented Dec 7, 2018

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.

@pwaller
Copy link

pwaller commented Dec 13, 2018

Heh, just came across this myself.

Preserving the comment structure is hard... golang/go#18593

Edit:

and another useful reference, seems it is being considered ongoing: golang/go#20744

Someone made another package representing the comments in another way which looks useful: https://github.com/dave/dst

@dave
Copy link

dave commented Jan 29, 2019

Hey there! Author of dst here... It should fix this problem. If you give it a go, let me know how it works...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants