segmentio/golines

line break between /* … */ comments and package statement removed

matthewhughes934 opened this issue · 0 comments

Given the following file (file.go):

/*
this is a description of the package
*/
package lib

func SomeLongFuncNameToBreakLineLength() {
}

Then running golines with a length that ensure we do some formatting removes the newline between the closing */ and the package declaration:

$ golines --max-len=20 file.go 
/*
this is a description of the package
*/package lib

func SomeLongFuncNameToBreakLineLength() {
}

If --max-len is not given, golines won't actually try and format anything and the the newline is preserved:

$ golines --max-len=20 file.go 
/*
this is a description of the package
*/
package lib

func SomeLongFuncNameToBreakLineLength() {
}

This appears to be related to an upstream issue in github.com/dave/dst/ dave/dst#69 (but sharing here for visibility). Since golines bails early if there's nothing to format

if linesToShorten == 0 {
in that case we don't call dst.{Parse/Printf} and hence the issue isn't triggered.

There's a fix for the issue upstream (dave/dst@5fa8d6e) but there's not been a new tag to include it. Testing that with go get github.com/dave/dst@5fa8d6ebe49a6b04afa15ee8f982d210f8a00b80 and I see the issue is resolved.

EDIT: upstream has created a new tag, here's a PR to include it #111