-
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.
- Loading branch information
Showing
19 changed files
with
319 additions
and
3 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,17 @@ | ||
# No Init Lists | ||
|
||
Do not use a list as the parameter for the `init/1` callback when implementing `gen_*` behaviours. | ||
It's semantically clearer to use a tuple or a map. | ||
[More info](https://erlangforums.com/t/args-in-gen-init-1/3169/5) | ||
|
||
> Works on `.beam` files? Yes! | ||
## Options | ||
|
||
- None. | ||
|
||
## Example | ||
|
||
```erlang | ||
{elvis_style, no_init_lists, #{}} | ||
``` |
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,3 @@ | ||
-module(example_behaviour). | ||
|
||
-callback example() -> atom(). |
15 changes: 15 additions & 0 deletions
15
test/examples/no_init_lists_examples/fail_no_init_lists.erl
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,15 @@ | ||
-module(fail_no_init_lists). | ||
|
||
-behaviour(gen_server). | ||
|
||
-export([start_link/1, init/1, handle_cast/2, handle_call/3]). | ||
|
||
start_link(AParam) -> | ||
gen_server:start_link(?MODULE, AParam, []). | ||
|
||
init([_AParam]) -> | ||
ok. | ||
|
||
handle_cast(_, _) -> ok. | ||
|
||
handle_call(_, _, _) -> ok. |
15 changes: 15 additions & 0 deletions
15
test/examples/no_init_lists_examples/fail_no_init_lists2.erl
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,15 @@ | ||
-module(fail_no_init_lists2). | ||
|
||
-behaviour(gen_server). | ||
|
||
-export([start_link/1, init/1, handle_cast/2, handle_call/3]). | ||
|
||
start_link(AParam) -> | ||
gen_server:start_link(?MODULE, AParam, []). | ||
|
||
init(_A = [1, 2, 3]) -> | ||
ok. | ||
|
||
handle_cast(_, _) -> ok. | ||
|
||
handle_call(_, _, _) -> ok. |
21 changes: 21 additions & 0 deletions
21
test/examples/no_init_lists_examples/fail_no_init_lists3.erl
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,21 @@ | ||
-module(fail_no_init_lists3). | ||
|
||
-behaviour(gen_server). | ||
|
||
-export([start_link/1, init/1, handle_cast/2, handle_call/3]). | ||
|
||
start_link(AParam) -> | ||
gen_server:start_link(?MODULE, AParam, []). | ||
|
||
init([_]) -> | ||
ok; | ||
|
||
init(_A = [1, 2, 3]) -> | ||
ok; | ||
|
||
init([undefined]) -> | ||
ok. | ||
|
||
handle_cast(_, _) -> ok. | ||
|
||
handle_call(_, _, _) -> ok. |
15 changes: 15 additions & 0 deletions
15
test/examples/no_init_lists_examples/fail_no_init_lists4.erl
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,15 @@ | ||
-module(fail_no_init_lists4). | ||
|
||
-behaviour(gen_server). | ||
-behaviour(example_behaviour). | ||
|
||
-export([init/1, handle_cast/2, handle_cast/3, handle_call/3]). | ||
-export([example/0]). | ||
|
||
init([]) -> {error, "should not be a list"}. | ||
|
||
handle_cast(_, _) -> ok. | ||
handle_cast(_, _, _) -> ok. | ||
handle_call(_, _, _) -> ok. | ||
|
||
example() -> ok. |
12 changes: 12 additions & 0 deletions
12
test/examples/no_init_lists_examples/fail_no_init_lists5.erl
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,12 @@ | ||
-module(fail_no_init_lists5). | ||
|
||
-behaviour(gen_fsm). | ||
|
||
-export([init/1, handle_sync_event/4, handle_event/3]). | ||
|
||
init([]) -> {error, "Don't use list for init/1"}. | ||
|
||
handle_sync_event(_, _, _, _) -> ok. | ||
|
||
handle_event(_, _, _) -> 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,7 @@ | ||
-module(fail_no_init_lists6). | ||
|
||
-behaviour(supervisor). | ||
|
||
-export([init/1]). | ||
|
||
init([]) -> {error, "Don't use list for init/1"}. |
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,9 @@ | ||
-module(fail_no_init_lists7). | ||
|
||
-behaviour(supervisor_bridge). | ||
|
||
-export([init/1, terminate/2]). | ||
|
||
init([]) -> {error, "Don't use list for init/1"}. | ||
|
||
terminate(_, _) -> ok. |
11 changes: 11 additions & 0 deletions
11
test/examples/no_init_lists_examples/fail_no_init_lists8.erl
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,11 @@ | ||
-module(fail_no_init_lists8). | ||
|
||
-behaviour(gen_event). | ||
|
||
-export([init/1, handle_event/2, handle_call/2]). | ||
|
||
init([]) -> {error, "Don't use list for init/1"}. | ||
|
||
handle_event(_, _) -> ok. | ||
|
||
handle_call(_, _) -> ok. |
21 changes: 21 additions & 0 deletions
21
test/examples/no_init_lists_examples/pass_no_init_lists.erl
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,21 @@ | ||
-module(pass_no_init_lists). | ||
|
||
-behaviour(gen_server). | ||
|
||
-export([start_link/0, init/1, handle_cast/2, handle_call/3]). | ||
|
||
start_link() -> | ||
gen_server:start_link(?MODULE, 1, []). | ||
|
||
init(1) -> | ||
ok; | ||
|
||
init([undefined]) -> | ||
ok; | ||
|
||
init([_]) -> | ||
ok. | ||
|
||
handle_cast(_, _) -> ok. | ||
|
||
handle_call(_, _, _) -> ok. |
18 changes: 18 additions & 0 deletions
18
test/examples/no_init_lists_examples/pass_no_init_lists2.erl
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,18 @@ | ||
-module(pass_no_init_lists2). | ||
|
||
-behaviour(gen_server). | ||
|
||
-export([start_link/0, init/1, init/2, handle_cast/2, handle_call/3]). | ||
|
||
start_link() -> | ||
gen_server:start_link(?MODULE, #{a => map}, []). | ||
|
||
init(#{}) -> | ||
ok. | ||
|
||
init([_], undefined) -> | ||
ok. | ||
|
||
handle_cast(_, _) -> ok. | ||
|
||
handle_call(_, _, _) -> ok. |
18 changes: 18 additions & 0 deletions
18
test/examples/no_init_lists_examples/pass_no_init_lists3.erl
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,18 @@ | ||
-module(pass_no_init_lists3). | ||
|
||
-behaviour(gen_server). | ||
|
||
-export([start_link/0, init/0, init/1, handle_cast/2, handle_call/3]). | ||
|
||
start_link() -> | ||
gen_server:start_link(?MODULE, {1, 2}, []). | ||
|
||
init({1, 2}) -> | ||
ok. | ||
|
||
init() -> | ||
ok. | ||
|
||
handle_cast(_, _) -> ok. | ||
|
||
handle_call(_, _, _) -> 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,8 @@ | ||
-module(pass_no_init_lists4). | ||
|
||
-export([start_link/1, init/1]). | ||
|
||
start_link(AParam) -> | ||
gen_server:start_link(?MODULE, [AParam], []). | ||
|
||
init([_AParam]) -> 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,8 @@ | ||
-module(pass_no_init_lists5). | ||
|
||
-behaviour(example_behaviour). | ||
|
||
-export([init/1, example/0]). | ||
|
||
init([]) -> {error, "can be a list"}. | ||
example() -> ok. |
Oops, something went wrong.