Removed unused package import logic #490
Merged
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.
Description
@LandonTClipp, I initially thought the current code to build imports list has special logic for vendored files. To prove it, I created a below fixture file:
And a test:
Moved libs to vendor, to see how vendored dependencies will be handled:
I tried different approaches and did go deeper into the x/tools but I can't make the Go SDK return a file location, it's always Go package path:
The https://pkg.go.dev/golang.org/x/tools@v0.1.11/go/packages library that's used to analyze an interface and fetch used types, relies on Go import semantics. There are no references to actual files on disk that are being used by mockery.
Why would there be any references to a file disk? 6 years ago, the tool was actually traversing the GOPATH paths to look for files to scan. The original author had the code that would transform file references to Go import packages aka. localize them. That wasn't perfect, so that’s why issues like #116 were created, with respective fixes.
Because the project doesn't traverse GOPATH anymore but uses only Go import abstractions from x/tools, there's no reason to keep that code anymore.
I marked this PR as bugfix as it removes code that is not used anymore, it only fixes the below issues:
.
in them are incorrectly imported in mocks #481Type of change
Version of Golang used when building/testing:
How Has This Been Tested?
As above.
Checklist