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: If a type is a record, it should be either opaque or not exported #264

Closed
elbrujohalcon opened this issue Feb 27, 2023 · 2 comments · Fixed by #300
Closed

New Rule: If a type is a record, it should be either opaque or not exported #264

elbrujohalcon opened this issue Feb 27, 2023 · 2 comments · Fixed by #300
Assignees
Labels
Milestone

Comments

@elbrujohalcon
Copy link
Member

elbrujohalcon commented Feb 27, 2023

No Exported Record Types

Brief Description

If your module defines a record and it also defines a type for it, that type should not be exported/accessible from the outside.

Should be on by default?

YES

Reasoning

Since the record is defined within the module, nobody from outside the module should know how to build an instance of that record. That means that the type associated with the record should not be public.
It can be an opaque type, so that other modules can pass around record instances but not [de]construct them. Or it can just be not exported so no modules other than the current one have knowledge about the record.

Examples

-module bad.
-record my_rec, {a, b, c}.

-type my_rec() :: #my_rec{}.
-export_type [my_rec/0].
-module good.
-record my_rec, {a, b, c}.

-opaque my_rec() :: #my_rec{}.
-export_type [my_rec/0].
-module also_good.
-record my_rec, {a, b, c}.

-type my_rec() :: #my_rec{}.
@elbrujohalcon elbrujohalcon added this to the 2.1.0 milestone Feb 27, 2023
@slyeargin slyeargin self-assigned this Feb 27, 2023
@paulo-ferraz-oliveira
Copy link
Collaborator

No maps? Or simply tuples instead of records?

@paulo-ferraz-oliveira
Copy link
Collaborator

It could even be part of the options: applies_to: [maps, records, tuples] where the default would be records (and/or tuples too).

@slyeargin slyeargin removed their assignment Feb 28, 2023
@maco maco self-assigned this Feb 28, 2023
@maco maco closed this as completed in #300 Mar 2, 2023
maco added a commit that referenced this issue Mar 2, 2023
Fix #264: New Rule: Private Data Types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants