Using importas
linter to require no alias to be provided for certain packages
#5221
-
I used this configuration to guarantee
Now, I discovered that some colleagues are adding an alias to the
But it leads to the following problem:
Is it possible to achieve this using To me not giving an alias should not be considered as a duplicate alias. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Hello, I think you can use: linters-settings:
importas:
# Do not allow non-required aliases.
# Default: false
no-extra-aliases: true https://golangci-lint.run/usage/linters/#importas $ golangci-lint run
importas.go:3:8: import "fmt" has alias "koo" which is not part of config (importas)
import koo "fmt"
^ |
Beta Was this translation helpful? Give feedback.
-
But then it would force all packages not mentioned in config to not have aliases, which would not work for our huge and old project. Note, we also have |
Beta Was this translation helpful? Give feedback.
-
I'm discovering the feature you mentioned it's very interesting - pkg: errors
alias: ""
- pkg: someinternalpkg/log
alias: "" I checked and this was possible without the - pkg: errors|someinternalpkg/log
alias: "" This was also possible - pkg: errors
alias: "errors"
- pkg: someinternalpkg/log
alias: "log" But, I do prefer the solution @ldez provided |
Beta Was this translation helpful? Give feedback.
-
Actually, this didn't work the way you would expect. It would force you to have these aliases (if you have |
Beta Was this translation helpful? Give feedback.
#5222