Tack.Credo.Check.NoCaptureOperator (pica v0.1.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 normal and works with any version of Elixir.

Explanation

Anonymous functions are written out, never with the capture shorthand.

CLAUDE.md, Conventions:

No capture-operator anonymous functions. Always write anonymous functions as fn descriptive_name -> body end — never the &/&1 shorthand (e.g. & &1.id, &(&1 + 1)). &Mod.fun/arity references are ok. Prefer descriptive argument names over positional &1.

The convention buys the same thing the "no abbreviations" rule buys: at every call site the argument has a name that says what it is, so a reader of Enum.filter(bids, fn bid -> bid.accepted? end) never has to look up what &1 was bound to.

# not ok
Enum.map(listings, & &1.code)
Enum.filter(prices, &(&1 > 0))

# ok
Enum.map(listings, fn listing -> listing.code end)
Enum.filter(prices, fn price -> price > 0 end)

# ok — a named function reference is not an anonymous function
Enum.map(codes, &String.upcase/1)
Enum.reduce(amounts, 0, &Kernel.+/2)

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.