diff --git a/src/elvis_style.erl b/src/elvis_style.erl index 86ea990..d4b3978 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -1230,14 +1230,7 @@ ms_transform_included(Config, Target, RuleConfig) -> -spec get_fun_2_ms_calls(ktn_code:tree_node()) -> [any()]. get_fun_2_ms_calls(Root) -> IsFun2MsFunctionCall = - fun(Node) -> - case ktn_code:type(Node) == call of - true -> - is_ets_fun2ms(Node); - false -> - false - end - end, + fun(Node) -> ktn_code:type(Node) == call andalso is_ets_fun2ms(Node) end, Functions = elvis_code:find(IsFun2MsFunctionCall, Root), ProcessResult = fun(Node) -> ktn_code:attr(location, Node) end, @@ -1250,7 +1243,7 @@ is_ets_fun2ms(Node) -> Fun2 = ktn_code:node_attr(function, Fun), Module = ktn_code:node_attr(module, Fun), - {ets, fun2ms} == {ktn_code:attr(value, Module), ktn_code:attr(value, Fun2)}. + ets == ktn_code:attr(value, Module) andalso fun2ms == ktn_code:attr(value, Fun2). -spec is_include_ms_transform(ktn_code:tree_node()) -> boolean(). is_include_ms_transform(Root) -> @@ -1259,12 +1252,7 @@ is_include_ms_transform(Root) -> andalso ktn_code:attr(value, Node) == "stdlib/include/ms_transform.hrl" end, - case elvis_code:find(Fun, Root) of - [_] -> - true; - _ -> - false - end. + [] /= elvis_code:find(Fun, Root). -spec no_throw(elvis_config:config(), elvis_file:file(), empty_rule_config()) -> [elvis_result:item()]. diff --git a/test/examples/custom_ms_transform_included.erl b/test/examples/custom_ms_transform_included.erl new file mode 100644 index 0000000..e53e561 --- /dev/null +++ b/test/examples/custom_ms_transform_included.erl @@ -0,0 +1,5 @@ +-module(custom_ms_transform_included). + +-export([test/0]). + +test() -> {this, is, "not", ets, my:fun2ms("It's my own")}. diff --git a/test/examples/double_include_ms_transform.erl b/test/examples/double_include_ms_transform.erl new file mode 100644 index 0000000..354fd28 --- /dev/null +++ b/test/examples/double_include_ms_transform.erl @@ -0,0 +1,8 @@ +-module(double_include_ms_transform). + +-include_lib("stdlib/include/ms_transform.hrl"). +-include_lib("stdlib/include/ms_transform.hrl"). + +-export([test/0]). + +test() -> ets:fun2ms(fun(_) -> ok end). diff --git a/test/examples/included_but_not_used_ms_transform.erl b/test/examples/included_but_not_used_ms_transform.erl new file mode 100644 index 0000000..cce7ba4 --- /dev/null +++ b/test/examples/included_but_not_used_ms_transform.erl @@ -0,0 +1,7 @@ +-module(included_but_not_used_ms_transform). + +-include_lib("stdlib/include/ms_transform.hrl"). + +-export([test/0]). + +test() -> ok. diff --git a/test/style_SUITE.erl b/test/style_SUITE.erl index 5232a48..c54551b 100644 --- a/test/style_SUITE.erl +++ b/test/style_SUITE.erl @@ -1405,6 +1405,26 @@ verify_ms_transform_included(Config) -> PassPath = "pass_ms_transform_included." ++ Ext, [] = elvis_core_apply_rule(Config, elvis_style, ms_transform_included, #{}, PassPath), + CustomFunctionPath = "custom_ms_transform_included." ++ Ext, + [] = + elvis_core_apply_rule(Config, + elvis_style, + ms_transform_included, + #{}, + CustomFunctionPath), + + IncludedButNotUsed = "included_but_not_used_ms_transform." ++ Ext, + [] = + elvis_core_apply_rule(Config, + elvis_style, + ms_transform_included, + #{}, + IncludedButNotUsed), + + DoubleInclude = "double_include_ms_transform." ++ Ext, + [] = + elvis_core_apply_rule(Config, elvis_style, ms_transform_included, #{}, DoubleInclude), + FailPath = "fail_ms_transform_included." ++ Ext, [_] = elvis_core_apply_rule(Config, elvis_style, ms_transform_included, #{}, FailPath), ok.