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

No empty lines before a simple error check not working #271

Closed
ftamhar opened this issue Jun 5, 2023 · 2 comments
Closed

No empty lines before a simple error check not working #271

ftamhar opened this issue Jun 5, 2023 · 2 comments

Comments

@ftamhar
Copy link

ftamhar commented Jun 5, 2023

If my code like this

package main

import "fmt"

func main() {
	var i int
	var err error
	i, err = fmt.Println("hello world")

	if err != nil {
		panic(err)
	}

	fmt.Println(i, err)
}

and I run gofumpt -l -w ., my expected result is like this

package main

import "fmt"

func main() {
	var i int
	var err error
	i, err = fmt.Println("hello world"
	if err != nil {
		panic(err)
	}

	fmt.Println(i, err)
}

but the result is like the first code snippet.

How do I achieve the results I expect?

@flan6
Copy link

flan6 commented Aug 22, 2023

I noticed that sometimes it does not work too.

@mvdan
Copy link
Owner

mvdan commented Aug 23, 2023

This check only triggers if the previous line follows the , err := pattern - note how it requires the token :=, it doesn't accept =. I agree that that's an unnecessary restriction, and we should make the formatter slightly more aggressive.

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

3 participants