Giter VIP home page Giter VIP logo

Comments (4)

bombsimon avatar bombsimon commented on July 27, 2024 1

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.

from wsl.

bombsimon avatar bombsimon commented on July 27, 2024

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

from wsl.

renkam avatar renkam commented on July 27, 2024

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.

from wsl.

bombsimon avatar bombsimon commented on July 27, 2024

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!

from wsl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.