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

golines format code that does not need to be shortened #123

Open
amandeepgautam opened this issue Mar 8, 2024 · 3 comments
Open

golines format code that does not need to be shortened #123

amandeepgautam opened this issue Mar 8, 2024 · 3 comments

Comments

@amandeepgautam
Copy link

I have the following line of code:

       Create(unique_id *UniqueId, name string) (*graphProto.CollectionProto, error)

which is formatted as:

       Create(
               unique_id *UniqueId,
               name string,
       ) (*graphProto.CollectionProto, error)

The initial one is less than 80 lines. It did not need any formatting.

@telemachus
Copy link
Contributor

Can you provide a minimal example file for reproduction, please?

@amandeepgautam
Copy link
Author

amandeepgautam commented Mar 9, 2024

@telemachus I am running into a different problem now while trying to get a minimal example working:

╰─ cat /tmp/minimal.go
type A interface {
	// This is a small example and it is not being formatted with single line comment.
	Create(unique_id *UniqueId, name string) (*apackagenm.CollectionProto, error)
}

I run the command ~/.vim-go/golines -w -m 80 /tmp/minimal.go and get a segfault.

╰─ ~/.vim-go/golines -w -m 80 /tmp/minimal.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x6f34c6]

goroutine 1 [running]:
go/token.(*File).Base(...)
	/usr/local/go/src/go/token/position.go:114
github.com/dave/dst/decorator.(*fileDecorator).fragment.func1(0xc000112f00)
	/home/cohesity/go/pkg/mod/github.com/dave/[email protected]/decorator/decorator-fragment.go:128 +0x4a6
github.com/dave/dst/decorator.(*fileDecorator).fragment(0xc00003ba48, {0x856f58, 0xc000112f00})
	/home/cohesity/go/pkg/mod/github.com/dave/[email protected]/decorator/decorator-fragment.go:170 +0xc3
github.com/dave/dst/decorator.(*Decorator).DecorateNode(0xc00014fa40, {0x856f58, 0xc000112f00})
	/home/cohesity/go/pkg/mod/github.com/dave/[email protected]/decorator/decorator.go:131 +0x11c
github.com/dave/dst/decorator.(*Decorator).DecorateFile(0xc000040740?, 0x0?)
	/home/cohesity/go/pkg/mod/github.com/dave/[email protected]/decorator/decorator.go:109 +0x1d
github.com/dave/dst/decorator.(*Decorator).ParseFile(0xc00014fa40, {0x0?, 0x7f08123b7108?}, {0x75b980?, 0xc000012480?}, 0xc000012480?)
	/home/cohesity/go/pkg/mod/github.com/dave/[email protected]/decorator/decorator.go:81 +0x5f
github.com/dave/dst/decorator.(*Decorator).Parse(...)
	/home/cohesity/go/pkg/mod/github.com/dave/[email protected]/decorator/decorator.go:67
github.com/dave/dst/decorator.Parse({0x75b980, 0xc000012480})
	/home/cohesity/go/pkg/mod/github.com/dave/[email protected]/decorator/helpers.go:17 +0x165
main.(*Shortener).Shorten(0xc00014f9d0, {0xc000170000?, 0xb8?, 0x200?})
	/home/cohesity/go/pkg/mod/github.com/segmentio/[email protected]/shortener.go:134 +0x34d
main.processFile(0xc00014f9d0, {0x7ffe09c0874d, 0xf})
	/home/cohesity/go/pkg/mod/github.com/segmentio/[email protected]/main.go:222 +0x16c
main.run()
	/home/cohesity/go/pkg/mod/github.com/segmentio/[email protected]/main.go:191 +0x29f
main.main()
	/home/cohesity/go/pkg/mod/github.com/segmentio/[email protected]/main.go:112 +0x14a

Because of the above segfault, I am not certain how the above example will be formatted, but that is what I have in my file which was formatted incorrectly.

@amandeepgautam
Copy link
Author

@telemachus Please find the example:

╰─ cat /tmp/minimal.go
package main

type A interface {
	// This is a small example with 79 char but is formatted when limit is 80 chars.
	Create(uniqueIdWithPaddingToRe int, nameWithPaddingToRe string) (*int, error)
}

func main() {}

Running golines:

╰─ ~/.vim-go/golines -m 80 --shorten-comments /tmp/minimal.go
package main

type A interface {
	// This is a small example with 79 char but is formatted when limit is 80
	// chars.
	Create(
		uniqueIdWithPaddingToRe int,
		nameWithPaddingToRe string,
	) (*int, error)
}

func main() {}

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