Credence.Pattern.NoRedundantBinarySyntax (credence v0.8.0)

Copy Markdown

Detects string literals needlessly wrapped in <<>> binary syntax.

In Elixir, strings are already UTF-8 encoded binaries. Wrapping a string literal in <<>> is completely redundant — <<"hello">> is identical to "hello". LLMs often add this wrapper when working with graphemes or character lists, carrying over intuitions from languages where strings and byte sequences are distinct types.

Bad

<<"hello">>
[<<"b">>, <<"a">>, <<"n">>]

Good

"hello"
["b", "a", "n"]

What is flagged

Any <<>> binary form containing a single string literal with no type specifiers. Multi-segment binaries (<<"a", "b">>), byte values (<<1, 2, 3>>), and typed segments (<<x::utf8>>, <<"a"::binary>>) are not flagged.

Sigil internals (~r/pattern/, ~s(text), ~w(words), etc.) are never flagged — their <<>> nodes are AST implementation details, not user-written binary syntax.

A <<"literal">> in a clause head is also left alone when a sibling clause of the same case/fn matches a real binary pattern (<<"/", rest::binary>>) — there the binary syntax is deliberately kept parallel, not redundant:

case url do
  <<"/">> -> root()                 # kept — parallels the next clause
  <<"/", rest::binary>> -> sub(rest)
end

Auto-fix

Unwraps the string literal by removing the surrounding << and >>.