From 24768868d116ef364b9c3bd947d5f09831a6e175 Mon Sep 17 00:00:00 2001 From: Oleg Butuzov Date: Mon, 17 Jan 2022 18:23:05 +0200 Subject: [PATCH 1/3] dev: adding new setting --- .golangci.example.yml | 4 +++- pkg/config/linters_settings.go | 5 +++-- pkg/golinters/importas.go | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.golangci.example.yml b/.golangci.example.yml index a785363d963f..7d779ea7db8e 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -498,8 +498,10 @@ linters-settings: max-decl-chars: 30 importas: - # if set to `true`, force to use alias. + # Do not allow unaliased imports of aliased packages. no-unaliased: true + # Do not allow non-required aliases. + no-extra-aliases: true # List of aliases alias: # using `servingv1` alias for `knative.dev/serving/pkg/apis/serving/v1` package diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 62edb3c86cb1..bdafcddf7bf5 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -352,8 +352,9 @@ type IfshortSettings struct { } type ImportAsSettings struct { - Alias []ImportAsAlias - NoUnaliased bool `mapstructure:"no-unaliased"` + Alias []ImportAsAlias + NoUnaliased bool `mapstructure:"no-unaliased"` + NoExtraAliases bool `mapstructure:"no-extra-aliases"` } type ImportAsAlias struct { diff --git a/pkg/golinters/importas.go b/pkg/golinters/importas.go index 523aa257b43a..ba217622062a 100644 --- a/pkg/golinters/importas.go +++ b/pkg/golinters/importas.go @@ -28,8 +28,11 @@ func NewImportAs(settings *config.ImportAsSettings) *goanalysis.Linter { lintCtx.Log.Infof("importas settings found, but no aliases listed. List aliases under alias: key.") // nolint: misspell } - err := analyzer.Flags.Set("no-unaliased", strconv.FormatBool(settings.NoUnaliased)) - if err != nil { + if err := analyzer.Flags.Set("no-unaliased", strconv.FormatBool(settings.NoUnaliased)); err != nil { + lintCtx.Log.Errorf("failed to parse configuration: %v", err) + } + + if err := analyzer.Flags.Set("no-extra-aliases", strconv.FormatBool(settings.NoUnaliased)); err != nil { lintCtx.Log.Errorf("failed to parse configuration: %v", err) } From 2fa8d1d8d0f25e6acb4051f2d6e33c1ed7209a3a Mon Sep 17 00:00:00 2001 From: Oleg Butuzov Date: Wed, 19 Jan 2022 09:22:29 +0200 Subject: [PATCH 2/3] chores: pinning `27e0a5d4dee2` as most recent version of `importas` --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7e1e1279931d..f84cadc5f394 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,7 @@ require ( github.com/jgautheron/goconst v1.5.1 github.com/jingyugao/rowserrcheck v1.1.1 github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af - github.com/julz/importas v0.0.0-20210419104244-841f0c0fe66d + github.com/julz/importas v0.0.0-20210922140945-27e0a5d4dee2 github.com/kisielk/errcheck v1.6.0 github.com/kulti/thelper v0.4.0 github.com/kunwardeep/paralleltest v1.0.3 diff --git a/go.sum b/go.sum index a686c7b85ac7..fc0253c043c7 100644 --- a/go.sum +++ b/go.sum @@ -456,6 +456,8 @@ github.com/juju/ratelimit v1.0.1/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSg github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julz/importas v0.0.0-20210419104244-841f0c0fe66d h1:XeSMXURZPtUffuWAaq90o6kLgZdgu+QA8wk4MPC8ikI= github.com/julz/importas v0.0.0-20210419104244-841f0c0fe66d/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSXO0DV0= +github.com/julz/importas v0.0.0-20210922140945-27e0a5d4dee2 h1:3sSu9gZvOTazWE4B4wsND7ofCsn75BD8Iz1OCBUZISs= +github.com/julz/importas v0.0.0-20210922140945-27e0a5d4dee2/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSXO0DV0= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= From e16a1ba026a3cee71d07b71e5b9aac2dcdd998a7 Mon Sep 17 00:00:00 2001 From: Oleg Butuzov Date: Wed, 19 Jan 2022 16:38:03 +0200 Subject: [PATCH 3/3] chores: pinning v0.1.0 as most recent version of `importas` --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f84cadc5f394..5744c969d776 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,7 @@ require ( github.com/jgautheron/goconst v1.5.1 github.com/jingyugao/rowserrcheck v1.1.1 github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af - github.com/julz/importas v0.0.0-20210922140945-27e0a5d4dee2 + github.com/julz/importas v0.1.0 github.com/kisielk/errcheck v1.6.0 github.com/kulti/thelper v0.4.0 github.com/kunwardeep/paralleltest v1.0.3 diff --git a/go.sum b/go.sum index fc0253c043c7..679ef7af0740 100644 --- a/go.sum +++ b/go.sum @@ -458,6 +458,8 @@ github.com/julz/importas v0.0.0-20210419104244-841f0c0fe66d h1:XeSMXURZPtUffuWAa github.com/julz/importas v0.0.0-20210419104244-841f0c0fe66d/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSXO0DV0= github.com/julz/importas v0.0.0-20210922140945-27e0a5d4dee2 h1:3sSu9gZvOTazWE4B4wsND7ofCsn75BD8Iz1OCBUZISs= github.com/julz/importas v0.0.0-20210922140945-27e0a5d4dee2/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSXO0DV0= +github.com/julz/importas v0.1.0 h1:F78HnrsjY3cR7j0etXy5+TU1Zuy7Xt08X/1aJnH5xXY= +github.com/julz/importas v0.1.0/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSXO0DV0= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=