From c56d7afb8aeb46d9976617dba1c0e9d12d63722a Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 2 Jun 2023 10:45:37 +0200 Subject: [PATCH] importas: fix duplication dectection when aliases use regular expression replacement pattern --- pkg/golinters/importas.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/golinters/importas.go b/pkg/golinters/importas.go index c7d8c175d0a8..b06aec7a3b4b 100644 --- a/pkg/golinters/importas.go +++ b/pkg/golinters/importas.go @@ -3,6 +3,7 @@ package golinters import ( "fmt" "strconv" + "strings" "github.com/julz/importas" //nolint:misspell "golang.org/x/tools/go/analysis" @@ -50,7 +51,8 @@ func NewImportAs(settings *config.ImportAsSettings) *goanalysis.Linter { uniqPackages[a.Pkg] = a } - if v, ok := uniqAliases[a.Alias]; ok { + // skip the duplication check when the alias is a regular expression replacement pattern (ie. contains `$`). + if v, ok := uniqAliases[a.Alias]; ok && !strings.Contains(a.Alias, "$") { lintCtx.Log.Errorf("invalid configuration, multiple packages with the same alias: alias=%s packages=[%s,%s]", a.Alias, a.Pkg, v.Pkg) } else { uniqAliases[a.Alias] = a