From d1f6cfc0ff908a8f3b3f1ca9b0f15dc855a72875 Mon Sep 17 00:00:00 2001 From: bormilan Date: Thu, 24 Oct 2024 18:03:32 +0200 Subject: [PATCH] add new test, and case --- Untitled | 1 + src/elvis_style.erl | 12 ++++++++++-- .../no_init_lists_examples/fail_no_init_lists5.erl | 12 ++++++++++++ .../no_init_lists_examples/fail_no_init_lists6.erl | 7 +++++++ .../no_init_lists_examples/fail_no_init_lists7.erl | 9 +++++++++ .../no_init_lists_examples/fail_no_init_lists8.erl | 11 +++++++++++ test/style_SUITE.erl | 8 ++++++++ 7 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 Untitled create mode 100644 test/examples/no_init_lists_examples/fail_no_init_lists5.erl create mode 100644 test/examples/no_init_lists_examples/fail_no_init_lists6.erl create mode 100644 test/examples/no_init_lists_examples/fail_no_init_lists7.erl create mode 100644 test/examples/no_init_lists_examples/fail_no_init_lists8.erl diff --git a/Untitled b/Untitled new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Untitled @@ -0,0 +1 @@ + diff --git a/src/elvis_style.erl b/src/elvis_style.erl index acbd339..2d757fc 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -151,7 +151,8 @@ -spec default(Rule :: atom()) -> DefaultRuleConfig :: term(). default(no_init_lists) -> - #{behaviours => [gen_server, gen_statem]}; + #{behaviours => + [gen_server, gen_statem, gen_fsm, supervisor, supervisor_bridge, gen_event]}; default(macro_names) -> #{regex => "^[A-Z](_?[A-Z0-9]+)*$"}; default(operator_spaces) -> @@ -1133,7 +1134,14 @@ no_init_lists(Config, Target, RuleConfig) -> andalso ktn_code:attr(name, Node) == init andalso ktn_code:attr(arity, Node) == 1 end, - [Init1Fun] = elvis_code:find(IsInit1Function, Root), + + Init1Fun = + case elvis_code:find(IsInit1Function, Root) of + [] -> + []; + [Fun] -> + Fun + end, FilterClauses = fun(Clause) -> diff --git a/test/examples/no_init_lists_examples/fail_no_init_lists5.erl b/test/examples/no_init_lists_examples/fail_no_init_lists5.erl new file mode 100644 index 0000000..07f34ca --- /dev/null +++ b/test/examples/no_init_lists_examples/fail_no_init_lists5.erl @@ -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. + diff --git a/test/examples/no_init_lists_examples/fail_no_init_lists6.erl b/test/examples/no_init_lists_examples/fail_no_init_lists6.erl new file mode 100644 index 0000000..38cbd9b --- /dev/null +++ b/test/examples/no_init_lists_examples/fail_no_init_lists6.erl @@ -0,0 +1,7 @@ +-module(fail_no_init_lists6). + +-behaviour(supervisor). + +-export([init/1]). + +init([]) -> {error, "Don't use list for init/1"}. diff --git a/test/examples/no_init_lists_examples/fail_no_init_lists7.erl b/test/examples/no_init_lists_examples/fail_no_init_lists7.erl new file mode 100644 index 0000000..6a0e4f3 --- /dev/null +++ b/test/examples/no_init_lists_examples/fail_no_init_lists7.erl @@ -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. diff --git a/test/examples/no_init_lists_examples/fail_no_init_lists8.erl b/test/examples/no_init_lists_examples/fail_no_init_lists8.erl new file mode 100644 index 0000000..3c48ccf --- /dev/null +++ b/test/examples/no_init_lists_examples/fail_no_init_lists8.erl @@ -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. diff --git a/test/style_SUITE.erl b/test/style_SUITE.erl index bb2a1ad..5464966 100644 --- a/test/style_SUITE.erl +++ b/test/style_SUITE.erl @@ -1530,11 +1530,19 @@ verify_no_init_lists(Config) -> FailPath2 = ExamplesDir ++ "fail_no_init_lists2." ++ Ext, FailPath3 = ExamplesDir ++ "fail_no_init_lists3." ++ Ext, FailPath4 = ExamplesDir ++ "fail_no_init_lists4." ++ Ext, + FailPath5 = ExamplesDir ++ "fail_no_init_lists5." ++ Ext, + FailPath6 = ExamplesDir ++ "fail_no_init_lists6." ++ Ext, + FailPath7 = ExamplesDir ++ "fail_no_init_lists7." ++ Ext, + FailPath8 = ExamplesDir ++ "fail_no_init_lists8." ++ Ext, [_] = elvis_core_apply_rule(Config, elvis_style, no_init_lists, #{}, FailPath), [_] = elvis_core_apply_rule(Config, elvis_style, no_init_lists, #{}, FailPath2), [_, _, _] = elvis_core_apply_rule(Config, elvis_style, no_init_lists, #{}, FailPath3), [_] = elvis_core_apply_rule(Config, elvis_style, no_init_lists, #{}, FailPath4), + [_] = elvis_core_apply_rule(Config, elvis_style, no_init_lists, #{}, FailPath5), + [_] = elvis_core_apply_rule(Config, elvis_style, no_init_lists, #{}, FailPath6), + [_] = elvis_core_apply_rule(Config, elvis_style, no_init_lists, #{}, FailPath7), + [_] = elvis_core_apply_rule(Config, elvis_style, no_init_lists, #{}, FailPath8), PassPath = ExamplesDir ++ "pass_no_init_lists." ++ Ext, PassPath2 = ExamplesDir ++ "pass_no_init_lists2." ++ Ext,