From 2d2b98e525f90b06fcc9b5a77aec11256ff84377 Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 16 Jun 2025 13:41:30 +0200 Subject: [PATCH] Update Elvis to 4.1.1, fix some warnings and enable their tests --- .github/workflows/ci.yml | 1 + elvis.config | 6 +++--- rebar.config | 2 +- src/ejabberd_auth.erl | 7 +++---- src/ejabberd_http.erl | 5 ++--- src/ejabberd_listener.erl | 6 +++--- src/mod_muc_admin.erl | 5 ++--- src/mod_scram_upgrade.erl | 6 ++---- src/pubsub_db_sql.erl | 2 +- 9 files changed, 18 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a39b5aadc..6c747e16b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,6 +120,7 @@ jobs: - run: make dialyzer - run: make test-eunit - run: make elvis + if: matrix.otp >= '26' - name: Check Production Release run: | diff --git a/elvis.config b/elvis.config index 074e13010..fb0f8b973 100644 --- a/elvis.config +++ b/elvis.config @@ -16,17 +16,17 @@ {elvis_style, function_naming_convention, disable}, {elvis_style, god_modules, #{limit => 300}}, {elvis_style, invalid_dynamic_call, disable}, - {elvis_style, macro_module_names, disable}, - {elvis_style, macro_names, disable}, {elvis_style, max_function_arity, disable}, % #{max_arity => 15}}, {elvis_style, nesting_level, disable}, {elvis_style, no_author, disable}, + {elvis_style, no_boolean_in_comparison, disable}, {elvis_style, no_catch_expressions, disable}, {elvis_style, no_debug_call, disable}, {elvis_style, no_if_expression, disable}, {elvis_style, no_import, disable}, - {elvis_style, no_match_in_condition, disable}, {elvis_style, no_nested_try_catch, disable}, + {elvis_style, no_operation_on_same_value, disable}, + {elvis_style, no_receive_without_timeout, disable}, {elvis_style, no_single_clause_case, disable}, {elvis_style, no_spec_with_records, disable}, {elvis_style, no_throw, disable}, diff --git a/rebar.config b/rebar.config index 7f07b4413..63c51b8fb 100644 --- a/rebar.config +++ b/rebar.config @@ -165,7 +165,7 @@ }]}}. {if_rebar3, {project_plugins, [configure_deps, {if_var_true, tools, rebar3_format}, - {if_var_true, tools, rebar3_lint} + {if_var_true, tools, {rebar3_lint, "4.1.1"}} ]}}. {if_not_rebar3, {plugins, [ deps_erl_opts, override_deps_versions2, override_opts, configure_deps diff --git a/src/ejabberd_auth.erl b/src/ejabberd_auth.erl index 419aad54d..f29ccbb96 100644 --- a/src/ejabberd_auth.erl +++ b/src/ejabberd_auth.erl @@ -423,9 +423,8 @@ count_users(Server, Opts) -> -spec get_password(binary(), binary()) -> false | [password()]. get_password(User, Server) -> - case get_password_with_authmodule(User, Server) of - {Passwords, _} -> Passwords - end. + {Passwords, _} = get_password_with_authmodule(User, Server), + Passwords. -spec get_password_s(binary(), binary()) -> password(). get_password_s(User, Server) -> @@ -815,7 +814,7 @@ db_user_exists(User, Server, Mod) -> end, case Val of {ok, _} -> - {true, Mod /= ejabberd_auth_anonymous} ; + {true, Mod /= ejabberd_auth_anonymous}; not_found -> {false, Mod /= ejabberd_auth_anonymous}; error -> diff --git a/src/ejabberd_http.erl b/src/ejabberd_http.erl index 8a3a45f54..aad7f7897 100644 --- a/src/ejabberd_http.erl +++ b/src/ejabberd_http.erl @@ -170,9 +170,8 @@ send_file(State, Fd, Size, FileName) -> try case State#state.sockmod of gen_tcp -> - case file:sendfile(Fd, State#state.socket, 0, Size, []) of - {ok, _} -> ok - end; + {ok, _} = file:sendfile(Fd, State#state.socket, 0, Size, []), + ok; _ -> case file:read(Fd, ?SEND_BUF) of {ok, Data} -> diff --git a/src/ejabberd_listener.erl b/src/ejabberd_listener.erl index 4fd7115a7..a3a9cc3ed 100644 --- a/src/ejabberd_listener.erl +++ b/src/ejabberd_listener.erl @@ -297,11 +297,11 @@ maybe_delete_udsocket_file(_Port) -> split_opts(Transport, Opts) -> maps:fold( fun(Opt, Val, {ModOpts, SockOpts}) -> - case OptVal = {Opt, Val} of + case {Opt, Val} of {ip, _} -> - {ModOpts, [OptVal|SockOpts]}; + {ModOpts, [{Opt, Val} | SockOpts]}; {backlog, _} when Transport == tcp -> - {ModOpts, [OptVal|SockOpts]}; + {ModOpts, [{Opt, Val} | SockOpts]}; {backlog, _} -> {ModOpts, SockOpts}; _ -> diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 1eadea684..77b46b275 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -2230,9 +2230,8 @@ find_services_validate(Global, _Name) when Global == global; Global == <<"global">> -> find_services(Global); find_services_validate(Service, Name) -> - case validate_muc(Service, Name) of - Service2 -> find_services(Service2) - end. + Service2 = validate_muc(Service, Name), + find_services(Service2). find_services(Global) when Global == global; Global == <<"global">> -> diff --git a/src/mod_scram_upgrade.erl b/src/mod_scram_upgrade.erl index f08c28631..7699006de 100644 --- a/src/mod_scram_upgrade.erl +++ b/src/mod_scram_upgrade.erl @@ -112,10 +112,8 @@ c2s_handle_sasl2_task_data({_, #{user := User, server := Server, serverkey = ServerKey, storedkey = StoredKey}), State2 = maps:remove(scram_upgrade, State), InlineEls2 = lists:keydelete(sasl_upgrade, 1, InlineEls), - case ejabberd_c2s:handle_sasl2_inline(InlineEls2, State2) of - {State3, NewEls, Results} -> - {success, NewEls, Results, State3} - end; + {State3, NewEls, Results} = ejabberd_c2s:handle_sasl2_inline(InlineEls2, State2), + {success, NewEls, Results, State3}; _ -> {abort, State} end. diff --git a/src/pubsub_db_sql.erl b/src/pubsub_db_sql.erl index a67654c7c..7a789e9ea 100644 --- a/src/pubsub_db_sql.erl +++ b/src/pubsub_db_sql.erl @@ -56,7 +56,7 @@ delete_subscription(SubID) -> "where subid = %(SubID)s")), ok. --spec update_subscription(#pubsub_subscription{}) -> ok . +-spec update_subscription(#pubsub_subscription{}) -> ok. update_subscription(#pubsub_subscription{subid = SubId} = Sub) -> delete_subscription(SubId), add_subscription(Sub).