-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
importas: allow repeated aliases #1960
Conversation
Could you explain why do you want to use several times the same alias for different imports? |
The way the file works now, I cannot configure these aliases with regex because both are
importas:
alias:
"$1$2": 'k8s.io/api/(\w+)/(v[\w\d]+)'
"$1$2": 'knative.dev/serving/pkg/apis/(\w+)/(v[\w\d]+)' |
Ok now I understand 👍 I would suggest something like that: importas:
# if set to `true`, force to use alias.
no-unaliased: true
# List of aliases
alias:
# using `servingv1` alias for `knative.dev/serving/pkg/apis/serving/v1` package
- pkg: knative.dev/serving/pkg/apis/serving/v1
alias: servingv1
# using `autoscalingv1alpha1` alias for `knative.dev/serving/pkg/apis/autoscaling/v1alpha1` package
- pkg: knative.dev/serving/pkg/apis/autoscaling/v1alpha1
alias: autoscalingv1alpha1
# You can specify the package path by regular expression,
# and alias by regular expression expansion syntax like below.
# see https://github.com/julz/importas#use-regular-expression for details
- pkg: knative.dev/serving/pkg/apis/(\w+)/(v[\w\d]+)
alias: $1$2 type ImportAsSettings struct {
Alias []ImportAsEntry
NoUnaliased bool `mapstructure:"no-unaliased"`
}
type ImportAsEntry struct {
Pkg string
Alias string
} |
The standalone importas takes arguments in the form "{package}:{alias}" and stores them in a map in which package is the key. The intent is to describe the one alias that is appropriate for a unique package path. We cannot use the package path as a map key due to Viper's dot notation. Instead use a list with package/alias pairs.
49babc0
to
eb65ac6
Compare
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hey, @cbandy — we just merged your PR to
By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests. Thanks again! |
As described in #1959, the standalone importas tool does not restrict an alias to a single package. This aligns our configuration with the standalone tool.
It is a breaking change, but another breaking change to this linter's configuration is waiting to be released in ffe8061.