MikaCredoRules.NoReimplementedHelper (MikaCredoRules v0.1.0)

Copy Markdown View Source

Helpers that already exist in a shared library must not be reimplemented locally.

Generic data helpers (atomize_keys/1, deep_merge/2, pluck/2, ...) get re-inlined as private functions over and over, and each copy drifts from the tested shared implementation. Call the shared helper instead of redefining it.

# BAD — local copy of a shared helper
defmodule MyApp.Worker do
  defp atomize_keys(map) do
    Map.new(map, fn {key, value} -> {String.to_existing_atom(key), value} end)
  end
end

# GOOD — the shared implementation is the only implementation
defmodule MyApp.Worker do
  def process(map), do: SharedUtils.Enum.atomize_keys(map)
end

Any def or defp whose name is a key of the :functions map is flagged, whatever its arity or body — a local function named after a shared helper is a drift hazard even when its body currently matches. Calls to the shared helpers are never flagged, only definitions.

Files matching an entry of :excluded_paths on a path-segment boundary are exempt, so the shared library itself can define the canonical implementations.