Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This uses the new package
golang.org/x/tools/go/packages
instead ofgolang.org/x/tools/go/loader
to load code, so that we can support checking packages that use Go modules with Go >= 1.11. This fixes #213.This preserves a bunch of code that probably isn't needed anymore;
go/packages
supports the Go package pattern thatgo list
uses (in fact, it appears to usego list
internally), so all the file system walking could be removed in favour of just relying on that. The current code is inefficient, since doingpackages.Load(&conf, "file=./mypkg/myfile.go")
actually loads the entire package, and there's no need to then dopackages.Load(&conf, "file=./mypkg/otherfile.go")
, since it's already loaded.There is one change here that I wasn't 100% sure about. The generator test cases have a test case for relative paths, something which I believe is moot with the new Go module system (and I'm not even sure if relative imports are officially supported in Go?). I have removed the test case in favour of using Go module imports instead of relative ones. Comments are welcome.
I added a
go.mod
file for good measure.Note that this changes Mockery to require Go >= 1.9, as
go/packages
does not support earlier versions.