-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #300 from inaka/264-opaque-records
Fix #264: New Rule: Private Data Types
- Loading branch information
Showing
9 changed files
with
211 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Private Data Types | ||
|
||
(since [3.0.0](https://github.com/inaka/elvis_core/releases/tag/3.0.0)) | ||
|
||
Exporting functions' internally-defined data types, in order to consume those | ||
types externally, results in tightly-coupled code. Modules should be responsible | ||
for defining their own internal data types. If these are needed outside the | ||
modules, they should be made | ||
[opaque](https://www.erlang.org/doc/reference_manual/opaques.html). | ||
|
||
> "Works on `.beam` file? Yes!" | ||
## Options | ||
|
||
- `apply_to :: [record | map | tuple]` | ||
- default: `record`. | ||
|
||
## Example | ||
|
||
```erlang | ||
{elvis_style, private_data_types} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-module(fail_private_data_types). | ||
|
||
-record(my_rec, {a :: integer(), b :: integer(), c :: integer()}). | ||
|
||
-type my_rec() :: #my_rec{}. | ||
-type my_tuple() :: {bitstring(), bitstring()}. | ||
-type my_map() :: map(). | ||
|
||
-export_type([my_rec/0]). | ||
-export_type([my_tuple/0]). | ||
-export_type([my_map/0]). | ||
|
||
-export([hello/0]). | ||
|
||
-spec hello() -> ok. | ||
hello() -> | ||
my_fun(#my_rec{a = 1, b = 2, c = 3}, {<<"hello">>, <<"world">>}, #{a => 1}). | ||
|
||
-spec my_fun(my_rec(), my_tuple(), my_map()) -> ok. | ||
my_fun(_Rec, _Tup, _Map) -> ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-module(pass_private_data_types). | ||
|
||
-record(my_rec, {a :: integer(), b :: integer(), c :: integer()}). | ||
|
||
-opaque my_rec() :: #my_rec{}. | ||
|
||
-export_type([my_rec/0]). | ||
|
||
-export([hello/0]). | ||
|
||
-spec hello() -> ok. | ||
hello() -> | ||
my_fun(#my_rec{a = 1, b = 2, c = 3}). | ||
|
||
-spec my_fun(my_rec()) -> ok. | ||
my_fun(_Rec) -> ok. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-module(pass_private_data_types2). | ||
|
||
-record(my_rec, {a :: integer(), b :: integer(), c :: integer()}). | ||
|
||
-type my_rec() :: #my_rec{}. | ||
-type my_tuple() :: {bitstring(), bitstring()}. | ||
-type my_map() :: map(). | ||
|
||
-export([hello/0]). | ||
|
||
-spec hello() -> ok. | ||
hello() -> | ||
my_fun(#my_rec{a = 1, b = 2, c = 3}, {<<"hello">>, <<"world">>}, #{a => 1}). | ||
|
||
-spec my_fun(my_rec(), my_tuple(), my_map()) -> ok. | ||
my_fun(_Rec, _Tup, _Map) -> ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-module(pass_private_data_types_elvis_attr). | ||
-elvis([{elvis_style, private_data_types, #{apply_to => [record, tuple]}}]). | ||
|
||
-record(my_rec, {a :: integer(), b :: integer(), c :: integer()}). | ||
|
||
-type my_rec() :: #my_rec{}. | ||
-type my_tuple() :: {bitstring(), bitstring()}. | ||
-type my_map() :: map(). | ||
|
||
-export([hello/0]). | ||
|
||
-spec hello() -> ok. | ||
hello() -> | ||
my_fun(#my_rec{a = 1, b = 2, c = 3}, {<<"hello">>, <<"world">>}, #{a => 1}). | ||
|
||
-spec my_fun(my_rec(), my_tuple(), my_map()) -> ok. | ||
my_fun(_Rec, _Tup, _Map) -> ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters