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
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:
parent
dd7c3d1a0f
commit
e5243324a6
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user