mvdan / gofumpt

A stricter gofmt
https://pkg.go.dev/mvdan.cc/gofumpt
BSD 3-Clause "New" or "Revised" License
3.15k stars 110 forks source link

Gofumpt removing newlines before comments #300

Open renbou opened 4 months ago

renbou commented 4 months ago

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 commented 4 months ago

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

renbou commented 4 months ago

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

dawiddzhafarov commented 3 months ago

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 commented 3 months ago

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

renbou commented 3 months ago

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 commented 3 months ago

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

seeruk commented 2 months ago

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?