AdRoll / rebar3_hank

The Erlang Dead Code Cleaner
MIT License
68 stars 9 forks source link

Disabling specific macros in specific files using rebar.config option does not work #190

Closed jesperes closed 2 years ago

jesperes commented 2 years ago

Bug Description

Using the ignore option in rebar.config to selectively disable some macros in some files (using wildcards) does not seem to work.

To Reproduce

Given the following project:

%% rebar.config
{plugins, [rebar3_hank]}.

{hank, [{ignore,
         [{"**/*.erl", [{unused_macros, ["FOO"]}
                       ]}
         ]}
       ]}.
%% src/hank_test.erl
-module(hank_test).

-define(FOO, ok).
-define(BAR, ok).

Run hank:

$ rebar3 hank
===> Looking for code to kill with fire...
===> The following pieces of code are dead and should be removed:
src/hank_test.erl:3: ?FOO is unused
src/hank_test.erl:4: ?BAR is unused

Expected Behavior

I would have expected hank to not report FOO as unused.

Additional Context

pbrudnick commented 2 years ago

Hey @jesperes , thank you! It's not actually a "bug" (maybe yes a desirable feature) since the ignore pattern via rebar.config is

ignore ([file:filename_all() | {file:filename_all(), hank_rule:t() | [hank_rule:t()]} | {file:filename_all(), hank_rule:t() | [hank_rule:t()], list()}]):

Check README section

What you can do to save this scenario is to set this in the module (hank_test.erl) itself:

-hank([{unused_macros, ["FOO"]}]).
jesperes commented 2 years ago
-hank([{unused_macros, ["FOO"]}]).

Yes, but this applies to many of our source files (they all include a common header file, and some of them use the macro, but many don't), and was hoping to avoid changing each of the source file.

But thanks for the quick reply, I'll figure out something.