AdRoll / rebar3_hank

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

[unused_macros] Detect when *wild* macros are unused #37

Open elbrujohalcon opened 3 years ago

elbrujohalcon commented 3 years ago

Currently, due to ktn_dodger limitations, some macro definitions are parsed as text. For instance, the one below…

-define(UNUSED_MACRO_WITH_BROKEN(CODE), case ?CODE of code -> ??CODE) .

ktn_dodger does its best to parse all macro definitions but when you just drop some random piece of code there, it might be impossible to parse it. In those scenarios, Hank sees the following syntax tree:

#tree{type = text,
      attr = #attr{pos = 10,ann = [],com = none},
      data = "-define( UNUSED_MACRO_WITH_BROKEN( CODE ) , case ?CODE of code -> ??CODE ) .\n"}

Basically a random block of text. It can't tell if that's a macro definition or not, let alone figure out the macro name and arity. So it doesn't tell you if that macro is actually unused.