unexported-return: do not allow unexported interfaces#1458
unexported-return: do not allow unexported interfaces#1458tie wants to merge 1 commit intomgechev:masterfrom
Conversation
| } | ||
|
|
||
| // UnexportedInterfacePointer returns an unexported interface pointer type from this package. | ||
| func UnexportedInterfacePointer() *unexportedInterface { // MATCH /exported func UnexportedInterfacePointer returns unexported type *foo.unexportedInterface, which can be annoying to use/ |
There was a problem hiding this comment.
Note, having pointer for an interface type as a result in 99.99% of cases is a mistake. Although, we can check it, I'd focus on a non-pointer result.
There was a problem hiding this comment.
Should we have a rule for detecting this? Or is it something already detected?
I have no computer with me to check unfortunately
There was a problem hiding this comment.
Returning an interface (vs concrete type) is usually not the best option (unless the func is a struct factory or something like that)
There was a problem hiding this comment.
@chavacava I agree, but here we have a pointer to an interface, which is even worse :)
I can imagine returning a settable value of an interface type and for that we return a pointer to it, but that's something I personally never saw in real life (neither I had a reason to do that in my own code). I saw this for input arguments that were meant to be the output ones as well, but not for the returned value.
The current implementation of
unexported-returnrule allows returning unexported interface types.Closes #1457