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

allow go statements invoke inline function #111

Closed
renkam opened this issue Jan 25, 2022 · 4 comments
Closed

allow go statements invoke inline function #111

renkam opened this issue Jan 25, 2022 · 4 comments
Labels
question Further information is requested

Comments

@renkam
Copy link

renkam commented Jan 25, 2022

Currently for code like this

go func() {
		doSomeStuff()
	}()

wsl reports go statements can only invoke functions assigned on line above

but here there are no function assignement and it is perfectly clear what is invoked

So please allow this king of invocation with go statement

@bombsimon
Copy link
Owner

I think you have something defined on the line above your go statement, I cannot reproduce with your code.

package main

func main() {
        go func() {
                fn()
        }()
}

func fn() {}
$ wsl ./main.go && echo $?
0

$ golangci-lint run --no-config --disable-all --enable wsl && echo $?
0

However, if I do something like this:

package main

func main() {
	x := 1
	go func() {
		fn()
	}()

	_ = x
}

func fn() {}

I can reproduce it:

$ wsl ./main.go && echo $?
./main.go:5: go statements can only invoke functions assigned on line above

The solution here would be to add a newline between your assignment and the go statement:

package main

func main() {
	x := 1

	go func() {
		fn()
	}()

	_ = x
}

func fn() {}
$ wsl ./main.go && echo $?
0

@bombsimon bombsimon added the question Further information is requested label Jan 25, 2022
@renkam
Copy link
Author

renkam commented Jan 25, 2022

There was a variable assigned line before. Indeed removing assignment results with no error.
So this should be really message about cuddle the go statement with something else than a function assignment.

@bombsimon
Copy link
Owner

Yes, this is a bad error message. If you look at the docs it comes from when you define a function but call another one. But in fact, this holds true for anything above, not just other functions.

I actually regret having so many different error messages, they could all just say something like "Should add an empty line to increase readability" or something similar. I have some plans to drop all checks that are not just missing empty lines. When doing this I will also change to a static single message for every situation. More information about that in #110.

@bombsimon
Copy link
Owner

I'll close this since the behaviour is expected. The real issue here is the bad error message. This is addressed in #110 and I don't think it's reasonable to change such behaviour without a new major release, that would f.ex. break existing regex ignores used in golangci-lint.

Let me know if you want me to re-open this issue to adress something else!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants