1
0
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:
Ludovic Fernandez
2025-06-18 16:58:16 +02:00
committed by GitHub
parent 24c008dd00
commit 87bd73b28e
2 changed files with 40 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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
}
}