Skip to content
Closed
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions rule/unexported_return.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ func exportedType(typ types.Type) bool {
case obj.Pkg() == nil:
case obj.Exported():
default:
_, ok := t.Underlying().(*types.Interface)
return ok
// If an alias itself is not exported, recursively check
// that the aliased type is exported.
return exportedType(t.Rhs())
}
return true
case *types.Named:
Expand Down
27 changes: 26 additions & 1 deletion testdata/golint/unexported_return.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ func ExportedIntReturner() int { // MATCH /exported func ExportedIntReturner ret
return int{}
}

type unexportedInterface interface {
UnexportedInterface()
}

// UnexportedInterfaceReturner returns an unexported interface type from this package.
func UnexportedInterfaceReturner() unexportedInterface {
return nil
}

type config struct {
N int
}
Expand All @@ -81,8 +90,24 @@ type b = 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/
func WithA(n int) b {
return func(c *config) {
c.N = n
}
}

// Check that we allow unexported type aliases if there is an “exported” type
// that can be used instead of an alias.

type funTypeAlias1 = func()

type funTypeAlias = funTypeAlias1

var funFunc func() func() // unaliased signature

func init() { funFunc = Fun }

// Fun returns an aliased function type.
func Fun() funTypeAlias {
return func() {}
}
Loading