From a484baba3dddfe12173f58efa0e47e0b46f73723 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Mon, 23 Sep 2024 22:13:33 +0100 Subject: [PATCH 1/2] Propose more `no_common_caveats_call` defaults --- MIGRATION.md | 2 ++ doc_rules/elvis_style/no_common_caveats_call.md | 6 +++++- test/examples/fail_no_call_classes.erl | 11 ++++++++++- test/style_SUITE.erl | 5 ++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index bef366ef..a3187e5d 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -26,6 +26,8 @@ This file's format is influenced by [Keep a Changelog](https://keepachangelog.co - your `no_debug_call` options to be the ones defined at +- your `no_common_caveats_call` options to be the ones defined at + On the other hand you may choose to not implement those changes and merely adapt your code. diff --git a/doc_rules/elvis_style/no_common_caveats_call.md b/doc_rules/elvis_style/no_common_caveats_call.md index 93e0f3cf..2645e653 100644 --- a/doc_rules/elvis_style/no_common_caveats_call.md +++ b/doc_rules/elvis_style/no_common_caveats_call.md @@ -5,7 +5,8 @@ The [Erlang Efficiency Guide](https://erlang.org/doc/efficiency_guide/commoncaveats.html) has a list of "Common Caveats" suggesting more efficient alternatives to several common functions. This rule provides warnings if you call "inefficient" functions with entirely equivalent (efficient) -alternatives. +alternatives. It also warns you about functions with a more explicit interface (e.g. `gen_server:call/3` +instead of `gen_server:call/2`) so you're sure to not have forgotten it. > Works on `.beam` file? Yes! @@ -17,6 +18,9 @@ alternatives. , {timer, send_interval, 2} , {timer, send_interval, 3} , {erlang, size, 1} + , {gen_statem, call, 2} + , {gen_server, call, 2} + , {gen_event, call, 3} ]`. **Notice**: this rule is not enforced by default. Check the diff --git a/test/examples/fail_no_call_classes.erl b/test/examples/fail_no_call_classes.erl index 1ec52b99..57b1cdda 100644 --- a/test/examples/fail_no_call_classes.erl +++ b/test/examples/fail_no_call_classes.erl @@ -13,4 +13,13 @@ fail() -> _ = erlang:size(<<"fail_size">>), _ = erlang:tuple_size({1,2,3}), - _ = erlang:byte_size(<<"ok_size">>). + _ = erlang:byte_size(<<"ok_size">>), + + _ = gen_server:call(self(), request), + _ = gen_server:call(self(), request, infinity), + + _ = gen_event:call(self(), self(), request), + _ = gen_event:call(self(), self(), request, infinity), + + _ = gen_statem:call(self(), request), + _ = gen_statem:call(self(), request, infinity). diff --git a/test/style_SUITE.erl b/test/style_SUITE.erl index 2bd2c5ad..5be09c99 100644 --- a/test/style_SUITE.erl +++ b/test/style_SUITE.erl @@ -1232,7 +1232,10 @@ verify_no_call_flavours(Config, {{erlang, size, 1}, 2}, {{timer, send_after}, 2}, {{timer, '_', '_'}, 4}, - {{'_', tuple_size, 1}, 1}], + {{'_', tuple_size, 1}, 1}, + {{gen_statem, call, 2}, 1}, + {{gen_server, call, 2}, 1}, + {{gen_event, call, 3}, 1}], lists:foreach(fun({FunSpec, ExpectedCount}) -> ThisRuleConfig = maps:from_list([{RuleConfigMapKey, [FunSpec]}]), From 2e908bde73db6999a6ba1542030cbad624368f5e Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Mon, 23 Sep 2024 22:14:10 +0100 Subject: [PATCH 2/2] Fix previous .md text (wrong rule name) --- doc_rules/elvis_style/no_call.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc_rules/elvis_style/no_call.md b/doc_rules/elvis_style/no_call.md index 14da14a6..9cf8622d 100644 --- a/doc_rules/elvis_style/no_call.md +++ b/doc_rules/elvis_style/no_call.md @@ -3,7 +3,7 @@ (since [0.4.0](https://github.com/inaka/elvis_core/releases/tag/0.4.0)) This rule raise a warning when certain functions are called. It is also used internally to implement -`no_debug_call` and `no_common_caveats` but, on its own, makes no checks on your code (the default +`no_debug_call` and `no_common_caveats_call` but, on its own, makes no checks on your code (the default `no_call_functions` list is empty). However, it is a convenient place to add your own list of calls to avoid (especially calls to third party libraries, where you can't just deprecate undesired functions).