Credence.Pattern.NoIsPrefixForNonGuard
(credence v0.5.0)
Copy Markdown
Detects def/defp functions with an is_ prefix, which in Elixir
is reserved for guard-safe functions defined with defguard or Erlang BIFs.
Why this matters
Elixir has a clear naming convention for boolean-returning functions:
is_foo/1→ must be usable in guard clauses (defguard) or Erlang BIFsfoo?/1→ regular boolean function (def/defp)
LLMs generate is_valid, is_palindrome, 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:
Bad
def is_palindrome(str), do: str == String.reverse(str)
defp is_valid_email(str), do: String.contains?(str, "@")Good
def palindrome?(str), do: str == String.reverse(str)
defp valid_email?(str), do: String.contains?(str, "@")Exceptions
Guard-safe BIFs from Erlang that legitimately use the is_ prefix
(like is_list/1, is_binary/1) are ignored so that user-defined wrapper
functions shadowing them are not mistakenly flagged.
Auto-fix
The fix renames the function definition and all bare (unqualified) call sites
within the same source file. is_valid_foo becomes valid_foo?.
Pass auto_fix_public: false to restrict the rename to defp only.
Useful when running file-by-file: external callers of a public function
live in other files and aren't visible to a per-file rule, so renaming
a def can leave imports / qualified calls referencing the old name.