Credence.Pattern.NoDestructureReconstruct (credence v0.4.3)

Copy Markdown

Detects patterns where a list is destructured into individual variables and then immediately reassembled into the same list.

Why this matters

LLMs destructure lists element-by-element because they think in terms of individual values, then reconstruct the list to pass to an Enum function. The reader sees named variables and expects them to be used individually, only to discover they're re-wrapped:

# Flagged — destructure then reconstruct
case String.split(ip, ".") do
  [p1, p2, p3, p4] ->
    Enum.all?([p1, p2, p3, p4], &valid_octet?/1)
end

# Idiomatic — bind as a whole, pattern match for length
case String.split(ip, ".") do
  [_, _, _, _] = parts ->
    Enum.all?(parts, &valid_octet?/1)
end

Auto-fix strategy

  1. Bind the whole list with = items on the pattern
  2. Replace the reconstructed list [a, b, c] in the body with items
  3. Check which individual variables are still used elsewhere in the body — replace unused ones with _ in the pattern

Flagged patterns

A list pattern [a, b, c, ...] in a case branch or function head where the body contains a list literal [a, b, c, ...] with the exact same variables in the same order.

Only flagged when the pattern contains 2 or more simple variables (not literals, patterns, or underscore-prefixed names).