Skip to content

Commit

Permalink
importas: fix duplication detection when aliases use regular expressi…
Browse files Browse the repository at this point in the history
…on replacement pattern (#3869)
  • Loading branch information
ldez committed Jun 2, 2023
1 parent dd7c3d1 commit e524332
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/golinters/importas.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package golinters
import (
"fmt"
"strconv"
"strings"

"github.com/julz/importas" //nolint:misspell
"golang.org/x/tools/go/analysis"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e524332

Please sign in to comment.