ForgeCredoChecks.NoKernelOpInPipeline (forge_credo_checks v0.4.0)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

Don't pipe into Kernel.<op>/2 — use the operator in infix position.

Why

LLMs produce code like list |> Enum.sort() |> Kernel.==(other) because they try to keep everything in one pipeline. In Elixir, comparison and boolean operators are infix; a qualified Kernel.==/2 call in a pipe reads as a function the LLM hallucinated, not a comparison.

Arithmetic operators (+, -, *, /) are NOT flagged — they have legitimate uses inside pipelines and the alternative is no clearer.

Bad

list |> Enum.uniq() |> Enum.sort() |> Kernel.==(other)

score |> calculate() |> Kernel.>=(threshold)

Good

# one-step pipe → infix
list |> Enum.sort() == other

# zero-step → just the comparison
calculate(score) >= threshold

# multi-step → parenthesize the pipeline
(list |> Enum.uniq() |> Enum.sort()) == other

Operators flagged

==, !=, ===, !==, <, >, <=, >=, and, or.

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.