Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importas: fix duplication detection when aliases use regular expression replacement pattern #3869

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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