Ale: Golang seems ignores vendor

Created on 2 Feb 2017  ยท  6Comments  ยท  Source: dense-analysis/ale

First of all, this plugin seems amazing!

I have just one small issue with go

One of the linters ignores the /vendor directory in the root path so always complain that it can't find any import because they live in /vendor rather than $GOPATH

bug

All 6 comments

There is a pull request open for fixing go build issues which may address the problem you are having: https://github.com/w0rp/ale/pull/270 Some more work is needed on it before it will work.

@DAddYE A pull request has just been merged which thoroughly includes and copies a whole host of files. Could you check if this has fixed your issues?

I believe the work from @DiscoViking and @joshuarubin has fixed this now.

Thanks guys! Works now!

Unfortunately, vendor/ is a specific case that does not yet fully work. I'm trying to figure it out right now, but things keep getting more and more complicated with this linter...

Lets say we have this dir structure in your $GOPATH:

foo/
โ”œโ”€โ”€ bar/
โ”‚ย ย  โ”œโ”€โ”€ bar.go
โ”œโ”€โ”€ baz/
โ”‚ย ย  โ”œโ”€โ”€ baz.go
โ”œโ”€โ”€ foo.go
โ”œโ”€โ”€ vendor/
โ”œย ย  โ”œโ”€โ”€ qux/
โ””ย ย  โ””   โ”” qux.go

Lets say foo/bar/bar.go has this:

type Bar struct {
    Qux qux.Qux
}

And foo/baz/baz.go has this:

type Baz struct {
    Qux qux.Qux
}

And foo/foo.go has this:

    var f bar.Bar
    var b baz.Baz

    f.Qux = b.Qux

If we lint foo/bar/bar.go then the copied directory structure looks like this:

foo/
โ”œโ”€โ”€ bar/
โ”‚ย ย  โ”œโ”€โ”€ bar.go
โ””โ”€โ”€ foo.go

This will fail to build with the current linter.

The reason for this is that the copied structure is in the primary $GOPATH. It didn't get the vendor directory, so it may not build at all, but lets say that qux was in the secondary $GOPATH.

What the compiler actually sees is roughly this:

// foo/bar/bar.go
type Bar struct {
    Qux $GOPATH.qux.Qux
}

// foo/baz/baz.go
type Baz struct {
    Qux $GOPATH.foo.vendor.qux.Qux
}

And the failure is in foo/foo.go when executing f.Qux = b.Qux which fails because they are not the same type.

I've been racking my brain about how to fix this issue. There is no issue unless there is a vendor directory. However, how to handle copying all the necessary files is not trivial.

I can symlink the vendor directory easily.

The problem is how to identify all the packages that depend on packages in that vendor directory. Once they are identified, they all have to be copied to the lint directory too.

I'm going to take a break. Let me know if you guys come up with something.

@joshuarubin probably is worth opening a new issue. I would suggest give an option to use go install $(go list ./... | grep -v /vendor/) which will cache things ... go build currently doesn't (_however it's planned sometime this year_)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sublee picture sublee  ยท  3Comments

amerov picture amerov  ยท  4Comments

glepnir picture glepnir  ยท  3Comments

garand picture garand  ยท  4Comments

trevordmiller picture trevordmiller  ยท  3Comments