Skip to content

Commit 59c6d29

Browse files
authored
importas: new option no-extra-aliases (#2494)
1 parent 68f530a commit 59c6d29

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

.golangci.example.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,10 @@ linters-settings:
554554
max-decl-chars: 30
555555

556556
importas:
557-
# if set to `true`, force to use alias.
557+
# Do not allow unaliased imports of aliased packages.
558558
no-unaliased: true
559+
# Do not allow non-required aliases.
560+
no-extra-aliases: true
559561
# List of aliases
560562
alias:
561563
# using `servingv1` alias for `knative.dev/serving/pkg/apis/serving/v1` package

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ require (
4343
github.com/jgautheron/goconst v1.5.1
4444
github.com/jingyugao/rowserrcheck v1.1.1
4545
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af
46-
github.com/julz/importas v0.0.0-20210419104244-841f0c0fe66d
46+
github.com/julz/importas v0.1.0
4747
github.com/kisielk/errcheck v1.6.0
4848
github.com/kulti/thelper v0.5.0
4949
github.com/kunwardeep/paralleltest v1.0.3

go.sum

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/linters_settings.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,9 @@ type IfshortSettings struct {
382382
}
383383

384384
type ImportAsSettings struct {
385-
Alias []ImportAsAlias
386-
NoUnaliased bool `mapstructure:"no-unaliased"`
385+
Alias []ImportAsAlias
386+
NoUnaliased bool `mapstructure:"no-unaliased"`
387+
NoExtraAliases bool `mapstructure:"no-extra-aliases"`
387388
}
388389

389390
type ImportAsAlias struct {

pkg/golinters/importas.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ func NewImportAs(settings *config.ImportAsSettings) *goanalysis.Linter {
2828
lintCtx.Log.Infof("importas settings found, but no aliases listed. List aliases under alias: key.") // nolint: misspell
2929
}
3030

31-
err := analyzer.Flags.Set("no-unaliased", strconv.FormatBool(settings.NoUnaliased))
32-
if err != nil {
31+
if err := analyzer.Flags.Set("no-unaliased", strconv.FormatBool(settings.NoUnaliased)); err != nil {
32+
lintCtx.Log.Errorf("failed to parse configuration: %v", err)
33+
}
34+
35+
if err := analyzer.Flags.Set("no-extra-aliases", strconv.FormatBool(settings.NoUnaliased)); err != nil {
3336
lintCtx.Log.Errorf("failed to parse configuration: %v", err)
3437
}
3538

0 commit comments

Comments
 (0)