AdRoll / rebar3_hank

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

Ignore unused NIF function parameters #65

Closed elbrujohalcon closed 3 years ago

elbrujohalcon commented 3 years ago

Describe the bug When defining a NIF, we need to write an Erlang function that will just raise an exception if used. Hank finds it and emits a warning for each one of its paramters.

To Reproduce Analyze a module with this function…

adler32_combine(_FirstAdler, _SecondAdler, _SecondSize) ->
    erlang:nif_error(undefined).

Expected behavior No warnings.

diegomanuel commented 3 years ago

Done! Now it should ignore the following examples:

hank_should_ignore_this_function_unused_params(_Ignore, _Me) ->
    erlang:nif_error(undefined).

and_also_this_one(_Ignore, Me, _Too) ->
    mylog:info(Me), % This line should not affect anything!
    erlang:nif_error(undefined, []).

and_this_one_too(_Ignore, _Me, Again) ->
    Msg = case Again of
      something -> "A message!";
      _ -> "Another message!"
    end,
    erlang:nif_error(Msg, [ignore, Again]).

even_with_multiple_clauses(A, B) -> A + B;
even_with_multiple_clauses(_, _) -> erlang:nif_error(no_warnings).