mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
importas: allow repeated aliases (#1960)
This commit is contained in:
parent
07a0568df1
commit
5c6adb63c9
7 changed files with 37 additions and 10 deletions
8
test/testdata/configs/importas.yml
vendored
8
test/testdata/configs/importas.yml
vendored
|
@ -1,5 +1,9 @@
|
|||
linters-settings:
|
||||
importas:
|
||||
alias:
|
||||
fff: fmt
|
||||
std_os: os
|
||||
- pkg: fmt
|
||||
alias: fff
|
||||
- pkg: os
|
||||
alias: std_os
|
||||
- pkg: github.com/pkg/errors
|
||||
alias: pkgerr
|
||||
|
|
8
test/testdata/configs/importas_strict.yml
vendored
8
test/testdata/configs/importas_strict.yml
vendored
|
@ -2,5 +2,9 @@ linters-settings:
|
|||
importas:
|
||||
no-unaliased: true
|
||||
alias:
|
||||
fff: fmt
|
||||
std_os: os
|
||||
- pkg: fmt
|
||||
alias: fff
|
||||
- pkg: os
|
||||
alias: std_os
|
||||
- pkg: github.com/pkg/errors
|
||||
alias: pkgerr
|
||||
|
|
3
test/testdata/importas.go
vendored
3
test/testdata/importas.go
vendored
|
@ -6,10 +6,13 @@ import (
|
|||
wrong_alias "fmt" // ERROR `import "fmt" imported as "wrong_alias" but must be "fff" according to config`
|
||||
"os"
|
||||
wrong_alias_again "os" // ERROR `import "os" imported as "wrong_alias_again" but must be "std_os" according to config`
|
||||
|
||||
wrong "github.com/pkg/errors" // ERROR `import "github.com/pkg/errors" imported as "wrong" but must be "pkgerr" according to config`
|
||||
)
|
||||
|
||||
func ImportAsWrongAlias() {
|
||||
wrong_alias.Println("foo")
|
||||
wrong_alias_again.Stdout.WriteString("bar")
|
||||
os.Stdout.WriteString("test")
|
||||
_ = wrong.New("baz")
|
||||
}
|
||||
|
|
3
test/testdata/importas_strict.go
vendored
3
test/testdata/importas_strict.go
vendored
|
@ -6,10 +6,13 @@ import (
|
|||
wrong_alias "fmt" // ERROR `import "fmt" imported as "wrong_alias" but must be "fff" according to config`
|
||||
"os" // ERROR `import "os" imported without alias but must be with alias "std_os" according to config`
|
||||
wrong_alias_again "os" // ERROR `import "os" imported as "wrong_alias_again" but must be "std_os" according to config`
|
||||
|
||||
wrong "github.com/pkg/errors" // ERROR `import "github.com/pkg/errors" imported as "wrong" but must be "pkgerr" according to config`
|
||||
)
|
||||
|
||||
func ImportAsStrictWrongAlias() {
|
||||
wrong_alias.Println("foo")
|
||||
wrong_alias_again.Stdout.WriteString("bar")
|
||||
os.Stdout.WriteString("test")
|
||||
_ = wrong.New("baz")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue