importas: fix duplication detection when aliases use regular expression replacement pattern (#3869)
Some checks failed
Release a tag / release (push) Has been cancelled
Release a tag / docker-release (map[Dockerfile:build/Dockerfile]) (push) Has been cancelled
Release a tag / docker-release (map[Dockerfile:build/alpine.Dockerfile]) (push) Has been cancelled

This commit is contained in:
Ludovic Fernandez 2023-06-02 11:01:43 +02:00 committed by GitHub
parent dd7c3d1a0f
commit e5243324a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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