Credence.Syntax.PreferCondDoKeyword
(credence v0.8.0)
Copy Markdown
Repairs cond -> written in place of cond do.
LLMs occasionally emit cond -> — mixing Rust/OCaml match-arm syntax into
Elixir — where Elixir requires cond do. The bare cond -> never parses, so
this is a REPAIR: replace the offending cond -> with cond do, opening the
block the trailing end was already waiting to close. cond do … end is the
only valid form, so the rewrite is behaviour-neutral.
Detection is driven by the parser itself. The rule replaces a single
cond -> occurrence and commits the result only when Code.string_to_quoted/1
then succeeds. A cond -> sitting inside a string, heredoc, or comment is
invisible to the parser, so replacing it never resolves a parse error and is
never the committed occurrence — it is left untouched even when the file is
unparseable for an unrelated reason.
Bad (won't parse)
cond ->
list == [] -> nil
true -> Enum.min(list)
endGood
cond do
list == [] -> nil
true -> Enum.min(list)
end