Credence.Rule.NoIsPrefixForNonGuard (credence v0.2.0)

Copy Markdown

Detects def/defp functions with an is_ prefix, which in Elixir is reserved for guard-safe functions defined with defguard.

Why this matters

Elixir has a clear naming convention for boolean-returning functions:

  • is_foo/1 → must be usable in guard clauses (defguard)
  • foo?/1 → regular boolean function (def / defp)

LLMs generate is_valid, is_palindrome, is_prime, etc. on virtually every boolean function because Python and JavaScript use is_ freely. In Elixir this misleads readers into thinking the function is guard-safe:

# Flagged — misleading convention
def is_palindrome(str), do: str == String.reverse(str)

# Idiomatic — ? suffix for non-guard booleans
def palindrome?(str), do: str == String.reverse(str)

Detection scope

Only def and defp clauses are flagged. defguard, defguardp, and defmacro are excluded since is_ is correct for those.

Severity

:warning