Credence.Pattern.NoGraphemePalindromeCheck
(credence v0.5.0)
Copy Markdown
Readability & performance rule: Detects the pattern of decomposing a string
into graphemes or a charlist, only to compare it with its own Enum.reverse.
This pattern creates an unnecessary intermediate list. Use String.reverse/1
and compare strings directly instead.
Bad
graphemes = String.graphemes(s)
graphemes == Enum.reverse(graphemes)
codepoints = String.to_charlist(s)
codepoints == Enum.reverse(codepoints)
normalized = s |> String.downcase() |> String.graphemes()
normalized == Enum.reverse(normalized)Good
cleaned = String.downcase(s)
cleaned == String.reverse(cleaned)