KogenCredo.Diff.Rules.NewSilentFallback (KogenCredo v0.1.0)

View Source

new-silent-fallback: the head has more silent catch-all handlers than the base.

A silent fallback is, with no logging or re-raise:

  • a clause of case, with ... else, receive, try ... else/catch whose pattern is a catch-all (_, _reason, a variable the body does not use, or {:error, <catch-all>}) and whose body is only a literal :ok, nil, [], %{}, "", false, {:ok, nil}, {:ok, []} or {:ok, %{}};
  • a rescue clause that binds nothing it uses and returns such a literal;
  • an added function clause whose parameters are all _ and whose body is such a literal, in a function with more than one clause.

A single-clause def f(_), do: nil and fn _ -> :ok end are not counted. New functions are compared with zero. Bodies with any other expression (a Logger call, raise, ...) are not silent.

Limits

Purely syntactic: a documented, intended _ -> nil is flagged the same. Fallbacks that return a non-literal default are not seen. Advisory by default; no precision has been measured.