Skip to content

add Credo.Check.Readability.NoCaptureOperator #1215

@markmark206

Description

@markmark206

(Thank you for this super-neat tool!;)

Please add a check (off by default, low priority) that would generate a warning on capture operator.

Reasoning:

Some teams might prefer explicit anonymous functions for ease of "at a glance" readability.

While the capture operator allows for shorter code, it adds cognitive overhead (and possibility of mis-reading) for the person quickly reading the code.

Code Examples:

  1. the "capture operator" version
current_execution.values
|> Enum.map(& &1.node_name)

(this code would be flagged by Credo.Check.Readability.NoCaptureOperator)

  1. the "anonymous function" version
current_execution.values
|> Enum.map(fn value -> value.node_name end)

Option 2 is obviously more verbose and not as clever, but it is also more explicit, and easier to correctly understand at a glance by developers even relatively new to Elixir, which is important for some teams.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions