AdRoll/rebar3_hank

New Rule: Unused Callbacks

elbrujohalcon opened this issue · 0 comments

Name

unused_callbacks

Brief Description

This rule would detect callbacks defined in a module (i.e. -callback the_callback…) that are not used within that module (i.e. nowhere in the module you can find M:the_callback(…).

Reasoning

The idea is that at some point somebody defined a callback as part of a particular behavior, but later on it was decided that the part of the behavior that used that callback was not needed anymore. The developer then removes the code but forgets to remove the callback definition… which stays, as dead code.

Refactoring Proposal

Remove the callback.

Implementation Trick

Finding all places where a particular function is used is not trivial (particularly when it's called dynamically… like in the case of behaviors). A good approach would be to implement the rule so that it will detect that the_callback is not used if it can't find the atom the_callback anywhere in the module, other than the definition of the callback.
This won't detect all cases where the callback is unused (the atom may be used for something else) but it will be very very close.
Remember: Hank's goal is to avoid false positives. In this case, Hank should not tell you that a callback is unused when it's actually used. It might not detect an unused callback if you use its name for something else (e.g. if you have 2 callbacks with the same name and different arities and you use only one of them)… 🤷‍♂️