Skip to content

Commit

Permalink
format: decl group allow first comment
Browse files Browse the repository at this point in the history
fixes mvdan#212
  • Loading branch information
Oiyoo committed Mar 21, 2022
1 parent f04017f commit dad8329
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions format/format.go
Expand Up @@ -316,13 +316,12 @@ func (f *fumpter) applyPre(c *astutil.Cursor) {
switch node := c.Node().(type) {
case *ast.File:
// Join contiguous lone var/const/import lines.
// Abort if there are empty lines or comments in between,
// including a leading comment, which could be a directive.
// Abort if there are empty lines or comments in between.
newDecls := make([]ast.Decl, 0, len(node.Decls))
for i := 0; i < len(node.Decls); {
newDecls = append(newDecls, node.Decls[i])
start, ok := node.Decls[i].(*ast.GenDecl)
if !ok || isCgoImport(start) || start.Doc != nil {
if !ok || isCgoImport(start) {
i++
continue
}
Expand Down
3 changes: 1 addition & 2 deletions testdata/scripts/decl-group-many.txt
Expand Up @@ -59,9 +59,8 @@ var v1 = "mixed"
const c1 = "mixed"

// comment, e.g. directive
var v1 = 's'

var (
v1 = 's'
v2 = 'd'
v3 = 'd'
)
Expand Down

0 comments on commit dad8329

Please sign in to comment.