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

Gofumpt removing newlines before comments #300

Open
renbou opened this issue Feb 26, 2024 · 7 comments
Open

Gofumpt removing newlines before comments #300

renbou opened this issue Feb 26, 2024 · 7 comments

Comments

@renbou
Copy link

renbou commented Feb 26, 2024

Why has gofumpt started removing newlines when it isn't needed? e.g. this is a transformation I'm constantly seeing now

Before formatting:
image

After formatting:
image

This just looks incredibly bad, to be honest...

@renbou
Copy link
Author

renbou commented Feb 26, 2024

Seems like this is happening specifically with the assignment := operator

@renbou
Copy link
Author

renbou commented Mar 1, 2024

This is also getting triggered JUST when the error is named err

@dawiddzhafarov
Copy link

According to the docs:

foo, err := processFoo()

if err != nil {
	return err
}

Will be always formatted to:

foo, err := processFoo()
if err != nil {
	return err
}

whether there is a comment or no I suppose

@mvdan
Copy link
Owner

mvdan commented Mar 30, 2024

This is working as intended; see "No empty lines before a simple error check" in the README.

@mvdan mvdan closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2024
@renbou
Copy link
Author

renbou commented Mar 30, 2024

Well, maybe this can be changed for the case with comments? I understand that it's working as intended right now, but is there some huge problem with changing it? I could probably make a PR for the change

@mvdan
Copy link
Owner

mvdan commented Mar 30, 2024

Personally I don't see the problem with removing empty lines when there are comments, but sure, I can review a PR.

@mvdan mvdan reopened this Mar 30, 2024
@seeruk
Copy link

seeruk commented Apr 15, 2024

I think this seems fine personally. The comment could be placed inside the block instead. On a simple error check, are you likely to be commenting something useful inbetween those lines too?

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

4 participants