Credence.Pattern.NoKernelOpInPipeline
(credence v0.4.4)
Copy Markdown
Detects qualified Kernel.op/2 calls used as steps in a pipeline.
LLMs produce code like list |> Enum.sort() |> Kernel.==(list) because
they try to keep everything in one pipeline. In Elixir, comparison and
boolean operators are used in infix position, not as qualified calls.
Bad
list |> Enum.uniq() |> Enum.sort() |> Kernel.==(list)
score |> calculate() |> Kernel.>=(threshold)Good
(list |> Enum.uniq() |> Enum.sort()) == list
calculate(score) >= thresholdAuto-fix
Extracts the operator from the pipeline and restructures:
- 0 remaining steps:
x |> Kernel.op(y)→x op y - 1 remaining step:
x |> f() |> Kernel.op(y)→f(x) op y - 2+ remaining steps:
x |> f() |> g() |> Kernel.op(y)→(x |> f() |> g()) op y
Arithmetic operators (+, -, *, /) are not flagged since
Kernel.+(n) in a pipe has no clearly better alternative.