mirror of
https://github.com/mgechev/revive.git
synced 2025-11-23 22:04:49 +02:00
unexported-return: fix type aliases support (#1408)
This commit is contained in:
committed by
GitHub
parent
24c008dd00
commit
87bd73b28e
@@ -78,7 +78,18 @@ func (*UnexportedReturnRule) Name() string {
|
||||
// It is imprecise, and will err on the side of returning true,
|
||||
// such as for composite types.
|
||||
func exportedType(typ types.Type) bool {
|
||||
switch t := types.Unalias(typ).(type) {
|
||||
switch t := typ.(type) {
|
||||
case *types.Alias:
|
||||
obj := t.Obj()
|
||||
switch {
|
||||
// Builtin types have no package.
|
||||
case obj.Pkg() == nil:
|
||||
case obj.Exported():
|
||||
default:
|
||||
_, ok := t.Underlying().(*types.Interface)
|
||||
return ok
|
||||
}
|
||||
return true
|
||||
case *types.Named:
|
||||
obj := t.Obj()
|
||||
switch {
|
||||
|
||||
28
testdata/golint/unexported_return.go
vendored
28
testdata/golint/unexported_return.go
vendored
@@ -58,3 +58,31 @@ type int struct{}
|
||||
func ExportedIntReturner() int { // MATCH /exported func ExportedIntReturner returns unexported type foo.int, which can be annoying to use/
|
||||
return int{}
|
||||
}
|
||||
|
||||
type config struct {
|
||||
N int
|
||||
}
|
||||
|
||||
// Option ...
|
||||
type Option = option
|
||||
|
||||
type option func(*config)
|
||||
|
||||
// WithN ...
|
||||
func WithN(n int) Option {
|
||||
return func(c *config) {
|
||||
c.N = n
|
||||
}
|
||||
}
|
||||
|
||||
type b = A
|
||||
|
||||
// A ...
|
||||
type A func(*config)
|
||||
|
||||
// WithA ...
|
||||
func WithA(n int) b { // MATCH /exported func WithA returns unexported type foo.b, which can be annoying to use/
|
||||
return func(c *config) {
|
||||
c.N = n
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user