github.com/Johnny2210/revive@v1.0.8-0.20210625134200-febf37ccd0f5/testdata/golint/unexported-return.go (about)

     1  // Test for unexported return types.
     2  
     3  // Package foo ...
     4  package foo
     5  
     6  type hidden struct{}
     7  
     8  // Exported returns a hidden type, which is annoying.
     9  func Exported() hidden { // MATCH /exported func Exported returns unexported type foo.hidden, which can be annoying to use/
    10  	return hidden{}
    11  }
    12  
    13  // ExpErr returns a builtin type.
    14  func ExpErr() error { // ok
    15    return nil
    16  }
    17  
    18  func (h hidden) ExpOnHidden() hidden { // ok
    19    return h
    20  }
    21  
    22  func (hidden) ForInterface() error {
    23    return nil
    24  }
    25  
    26  // Interface is exported.
    27  type Interface interface {
    28  	ForInterface() error
    29  }
    30  
    31  // ExportedAsInterface returns a hidden type as an exported interface, which is fine.
    32  func ExportedAsInterface() Interface { // ok
    33  	return Exported()
    34  }
    35  
    36  // T is another test type.
    37  type T struct{}
    38  
    39  // MethodOnT returns a hidden type, which is annoying.
    40  func (T) MethodOnT() hidden { // MATCH /exported method MethodOnT returns unexported type foo.hidden, which can be annoying to use/
    41  	return hidden{}
    42  }
    43  
    44  // ExpT returns a T.
    45  func ExpT() T { // ok
    46  	return T{}
    47  }
    48  
    49  func unexp() hidden { // ok
    50  	return hidden{}
    51  }
    52  
    53  // This is slightly sneaky: we shadow the builtin "int" type.
    54  
    55  type int struct{}
    56  
    57  // ExportedIntReturner returns an unexported type from this package.
    58  func ExportedIntReturner() int { // MATCH /exported func ExportedIntReturner returns unexported type foo.int, which can be annoying to use/
    59  	return int{}
    60  }