elvis_core icon indicating copy to clipboard operation
elvis_core copied to clipboard

False positive on used_ignored_variable inside macros

Open fen-pl opened this issue 1 year ago • 0 comments

Bug Description

When an unused variable has a name and is provided in a macro, it is reported by used_ignored_variable. Naming such variables contributes to the code readability. Similar variables used outside macro context are not reported.

To Reproduce

Run elvis on this snippet:

-module(test).

-include_lib("stdlib/include/assert.hrl").

-define(MYMACRO(X), fun(X) -> ok end).

-export([do/0]).

do() ->
    List = [{a, b}, {c, d}],
    {_Key, b} = lists:keyfind(a, 1, List),
    ?assertMatch({_K, _}, lists:keyfind(a, 1, List)),
    ?MYMACRO({_P1, _}).

With this config:

[
    {
        elvis,
        [
            {config, [
                #{
                    dirs => [".", "src"],
                    filter => "*.erl",
                    ruleset => erl_files,
                    rules =>
                        [
                            {elvis_style, no_author, disable}
                        ]
                }
            ]}
        ]
    }
].

Result:

# src/test.erl [FAIL]
  - used_ignored_variable (https://github.com/inaka/elvis_core/tree/main/doc_rules/elvis_style/used_ignored_variable.md)
    - Ignored variable is being used on line 12 and column 19.
    - Ignored variable is being used on line 13 and column 15.

Expected Behavior

Elvis allows the usage of named unused variables inside macros.

Additional Context

  • OS: Linux
  • Erlang version: 24.3

fen-pl avatar Jul 16 '24 11:07 fen-pl