mix kogen.unused_public (KogenCredo v0.1.0)

View Source

Lists public functions with no caller in the project's compiled modules.

mix kogen.unused_public [--format text|json] [--fail]
  [--entrypoint-module REGEX_OR_NAME]... [--entrypoint-function Mod.fun/arity]...
  [--ignore-module REGEX_OR_NAME]...

This is advisory: it exits 0 unless --fail is passed. With --fail it exits 1 when there are findings and 2 when the analysis was incomplete (some modules had no debug info or could not be read), because skipped modules hide callers and an incomplete run must not pass. The analysis is described, with its limits, in KogenCredo.UnusedPublic. It is not whole-program proof; read that moduledoc before acting on a finding.

Compile-state requirements

  • The task runs mix compile first (without --force), in the current MIX_ENV, so the analysed beams match the sources. It reads Mix.Project.compile_path/0 (_build/<env>/lib/<app>/ebin); in an umbrella it reads every child app so cross-app calls are seen.
  • Beams need debug info (the default). Modules compiled with debug_info: false are listed as skipped and are not counted as callers, which can produce false findings; the task says so on stderr.
  • Only the modules compiled for this MIX_ENV are callers. Test code is not (it is compiled in memory by mix test), so a function used only by tests is reported, on purpose: "no plumbing without a caller".
  • Do not run it on a library whose public functions are API for other projects, or list those modules with --ignore-module.

Option values

--entrypoint-module, --ignore-module: a module name such as MyApp.Jobs matches exactly; a value wrapped in slashes, e.g. /Worker$/, is a regex. Passing --entrypoint-module replaces the default patterns (controllers, routers, channels, sockets and Mix.Tasks.*).