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

Empty lines inside structs/functions are sometimes removed #65

Open
horenmar opened this issue Apr 24, 2022 · 2 comments
Open

Empty lines inside structs/functions are sometimes removed #65

horenmar opened this issue Apr 24, 2022 · 2 comments

Comments

@horenmar
Copy link

I have a source file that uses cgo a lot, and running it through dst causes (some) empty lines in structs/functions to be removed.

I tried some testing, and I am not entirely sure what causes the empty lines to be removed, because e.g. this struct is left alone

type StructTest struct {
	aaa int32

	b int32
}

but a similar struct

type AType struct {
	c      *C.StructNameCensored
	f SomeComplexGoType

	using int32
}

has the empty line removed, so it looks like this:

type AType struct {
	c     *C.StructNameCensored
	f     SomeComplexGoType
	using int32
}

I also have a similar issue inside (some) functions -- I guess this is related to the C APIs? However, the newline between the package line and the copyright notice is also removed:

// Copyright 2020 Pexeso Inc. All Rights reserved.

package matcher
@dave
Copy link
Owner

dave commented Apr 24, 2022

Thanks for this. It unlikely that I'll have any time to fix bugs like these but it's good to have them documented here.

@dave
Copy link
Owner

dave commented May 31, 2022

Hery @horenmar I'm unable to reproduce this bug... Here's the code I'm using... perhaps you can tweak it to show when this bug appears?

package main

import (
	"go/format"
	"go/token"
	"log"
	"os"

	"github.com/dave/dst/decorator"
)

func main() {

	code := `package main
        
type AType struct {
	c *C.StructNameCensored
	f SomeComplexGoType

	using int32
}`

	file, err := decorator.NewDecorator(token.NewFileSet()).Parse(code)
	if err != nil {
		log.Fatal(err)
	}

	restoredFset, restoredFile, err := decorator.RestoreFile(file)
	if err != nil {
		log.Fatal(err)
	}

	if err := format.Node(os.Stdout, restoredFset, restoredFile); err != nil {
		log.Fatal(err)
	}
}

Output:

package main

type AType struct {
        c *C.StructNameCensored
        f SomeComplexGoType

        using int32
}

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

2 participants