Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Rule: Export All Used Types #265

Closed
elbrujohalcon opened this issue Feb 27, 2023 · 1 comment
Closed

New Rule: Export All Used Types #265

elbrujohalcon opened this issue Feb 27, 2023 · 1 comment
Assignees
Labels
Milestone

Comments

@elbrujohalcon
Copy link
Member

elbrujohalcon commented Feb 27, 2023

Export All Used Types

Brief Description

The idea is to emit a warning every time a spec for an exported function uses a local type that's not exported.

Should be on by default?

YES

Reasoning

If you put a type in a spec of an exported function, that means that people writing modules that call that function should know what that type is and they may as well pass instances of that type around before calling your function. So, to add their own specs, and also to keep dialyzer messages cleaner, they should put your_mod:your_type() in their specs, instead of the actual definition of the type.
To be able to do that, the type must be exported.

Refactoring Proposal

Add the non-exported types to an -export_type(…). attribute.

Examples

-module bad.

-type my_type() :: my | type.

-export [my_fun/1].

-spec my_fun(my_type()) -> my_type().
my_fun(my) -> type;
my_fun(type) -> my.
-module good.

-type my_type() :: my | type.
-export_type [my_type/0].

-export [my_fun/1].

-spec my_fun(my_type()) -> my_type().
my_fun(my) -> type;
my_fun(type) -> my.
@elbrujohalcon elbrujohalcon added this to the 2.1.0 milestone Feb 27, 2023
@paulo-ferraz-oliveira
Copy link
Collaborator

Oh, yeah, we ARE missing this one. ❤️

@maco maco self-assigned this Feb 27, 2023
@maco maco closed this as completed in 72df3ba Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants