Skip to content

Commit b2e24d6

Browse files
authored
importas: allow multiple empty aliases (#5222)
1 parent dafd655 commit b2e24d6

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

pkg/golinters/importas/importas.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ func New(settings *config.ImportAsSettings) *goanalysis.Linter {
5151
uniqPackages[a.Pkg] = a
5252
}
5353

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, "$") {
54+
// Skips the duplication check when:
55+
// - the alias is empty.
56+
// - the alias is a regular expression replacement pattern (ie. contains `$`).
57+
v, ok := uniqAliases[a.Alias]
58+
if ok && a.Alias != "" && !strings.Contains(a.Alias, "$") {
5659
lintCtx.Log.Errorf("invalid configuration, multiple packages with the same alias: alias=%s packages=[%s,%s]", a.Alias, a.Pkg, v.Pkg)
5760
} else {
5861
uniqAliases[a.Alias] = a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//golangcitest:args -Eimportas
2+
//golangcitest:config_path testdata/importas_several_empty_aliases.yml
3+
//golangcitest:expected_exitcode 0
4+
package testdata
5+
6+
import (
7+
"fmt"
8+
"math"
9+
"os"
10+
)
11+
12+
func _() {
13+
fmt.Println("a")
14+
fmt.Fprint(os.Stderr, "b")
15+
println(math.MaxInt)
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
linters-settings:
2+
importas:
3+
alias:
4+
- pkg: fmt
5+
alias: ''
6+
- pkg: os
7+
alias: ''
8+
- pkg: math
9+
alias: ''

0 commit comments

Comments
 (0)