View Source unused_callbacks (rebar3_hank v1.4.0)

A rule to detect unused callbacks.

This rule will check all callbacks defined in a module and find those that are not used anywhere in the module itself.

It will emit a warning if it can't find the callback's atom name being used anywhere within a module. It will NOT emit a warning if an atom named as a callback is being used, no matter for what that atom is used.

This limitation is due to the fact that there are many ways to call a function in Erlang (particularly when dynamic calls are involved).

The assumption is that if you define a callback for a behavior, your generic module (where the callback is defined) should call that function at some point, using the implementation provided by the specific module (the one that implements the behavior).

To avoid this warning, remove the unused callback definition.

note

Note

For this rule to apply, it's assumed that callbacks defined for a particular behavior are only used within the same module that defines it. If you define behaviors in your project and you use their callbacks from other modules, you can add an ignore rule in rebar.config for it.

Link to this section Summary

Functions

Rule ignore specifications. Example:
       -hank([{unused_callbacks,
               [all, %% Will ignore all versions of the all callback (i.e. any arity)
                {just, 1} %% Will ignore just(term()) but not just() nor just(_, _) callbacks
               ]},
       

Link to this section Functions

Link to this function

ignored(Pattern, Callback)

View Source
-spec ignored(hank_rule:ignore_pattern(), term()) -> boolean().
Rule ignore specifications. Example:
       -hank([{unused_callbacks,
               [all, %% Will ignore all versions of the all callback (i.e. any arity)
                {just, 1} %% Will ignore just(term()) but not just() nor just(_, _) callbacks
               ]},