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
bug: redundant-import-alias
rule check for import path instead of package name
#936
Comments
This update has to be performed manually, as the following check need to be disabled: 1. `unchecked-type-assertion` ```go cl := meta.(*client.Client) ``` 2. `import-alias-naming` This check requires a specific alias naming for imports. 3. `redundant-import-alias` This check will fail if the alias is the last part of the import path, although the package name may differ. See mgechev/revive#936 for more deetails.
Hi @candiduslynx, thank you for reporting the issue. |
The only viable solution for that seems to be using
The problem of this solution is that package.Load uses |
Another possible solution would be to load only package name when traversing the vendored imports, but this will also require an additional effort:
|
There are two ways of having the deps: |
IMO this check just needs to be retired, as it's not usable with some major SDKs. Or, at the very least, the package name should be determined by an updated process (it will still be a hack and won't work for the example in the issue description, where the package name doesn't match the directory name):
I'm not entirely sure what to do with import apiv2 "cloud.google.com/go/run/apiv2" |
Note that the actual package name can be v1: https://pkg.go.dev/k8s.io/api/core/v1. |
Note that this linter directly conflicts with what goimports does for packages like the one denisvmedia posted above. if the package name is literally v1, then goimports will change import "github.com/foo/bar/v1" to import v1 "gitub.com/foo/bar/v1" ...and then revive will tell you that's redundant. Now, I don't 100% agree with goimports aliasing a thing to the same name... and I think it's generally dumb to call a package literally v1. BUT, if I have to pick who has to comply with who, I gotta say that revive should not call anything that goimports does "incorrect". |
Describe the bug
When checking
redundant-import-alias
the code will only look at the import path, whereas the proper way would've been to check the imported package name.I've seen this with
import apiv2 "cloud.google.com/go/run/apiv2"
(the code is underapiv2
directory, but the package name isrun
: https://pkg.go.dev/cloud.google.com/go/run/apiv2)To Reproduce
Steps to reproduce the behavior:
redundant
with the following content (note that the package name must be different):import redundant "path/to/redundant"
Expected behavior
No issue is presented, as the alias is used to override the package name, not the path.
Logs
This is printed when importing:
The text was updated successfully, but these errors were encountered: