Credence.Syntax.NoElseIf (credence v0.8.0)

Copy Markdown

Detects and rewrites Python-style else if (two words) chains to idiomatic cond.

LLMs translating from Python emit else if (two words) which in Elixir parses as else + nested if needing its own end, causing persistent TokenMissingError. Converting else if chains to cond is behaviour-preserving and idiomatic.

Bad (won't parse as intended)

if n == 0 do
  list
else if n >= length(list) do
  []
else
  List.take(list, length(list) - n)
end

Good

cond do
  n == 0 -> list
  n >= length(list) -> []
  true -> List.take(list, length(list) - n)
end