Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive on used_ignored_variable inside macros #352

Open
fenek opened this issue Jul 16, 2024 · 0 comments
Open

False positive on used_ignored_variable inside macros #352

fenek opened this issue Jul 16, 2024 · 0 comments
Labels
Milestone

Comments

@fenek
Copy link

fenek commented Jul 16, 2024

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
@fenek fenek added the bug label Jul 16, 2024
@elbrujohalcon elbrujohalcon changed the title used_ignored_variable reports false positive inside macros False positive on used_ignored_variable inside macros Jul 16, 2024
@elbrujohalcon elbrujohalcon added this to the 4.0.0 milestone Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants