Skip to content

Commit e524332

Browse files
authored
importas: fix duplication detection when aliases use regular expression replacement pattern (#3869)
1 parent dd7c3d1 commit e524332

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pkg/golinters/importas.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package golinters
33
import (
44
"fmt"
55
"strconv"
6+
"strings"
67

78
"github.com/julz/importas" //nolint:misspell
89
"golang.org/x/tools/go/analysis"
@@ -50,7 +51,8 @@ func NewImportAs(settings *config.ImportAsSettings) *goanalysis.Linter {
5051
uniqPackages[a.Pkg] = a
5152
}
5253

53-
if v, ok := uniqAliases[a.Alias]; ok {
54+
// skip the duplication check when the alias is a regular expression replacement pattern (ie. contains `$`).
55+
if v, ok := uniqAliases[a.Alias]; ok && !strings.Contains(a.Alias, "$") {
5456
lintCtx.Log.Errorf("invalid configuration, multiple packages with the same alias: alias=%s packages=[%s,%s]", a.Alias, a.Pkg, v.Pkg)
5557
} else {
5658
uniqAliases[a.Alias] = a

0 commit comments

Comments
 (0)