jfmengels / elm-review-code-style / NoSimpleLetBody

rule : Review.Rule.Rule

Reports when a let expression's body is a simple reference to a value declared in the let expression.

🔧 Running with --fix will automatically remove most of the reported errors.

config =
    [ NoSimpleLetBody.rule
    ]

The reasoning is that it is not necessary to assign a name to the result of a let expression, since they are redundant with the value or function containing the expression.

If it feels necessary to give a name anyway because it helps clarify the context, then it might be a sign that the computation of that value should be extracted to a function.

Let expressions will be reported regardless of whether they're at the root of a function or deeply nested.

Fail

a =
    let
        b =
            1

        c =
            b + 1
    in
    c

Success

Anything that is not simply a reference to a value declared in the let expression is okay.

a =
    let
        b =
            1
    in
    b + 1

The rule will not report when the referenced value was destructured in the let expression.

first tuple =
    let
        ( value, _ ) =
            tuple
    in
    value

When (not) to enable this rule

This rule resolves a minor style issue, and may not be worth enforcing depending on how strongly you feel about this issue.

Try it out

You can try this rule out by running the following command:

elm-review --template jfmengels/elm-review-code-style/example --rules NoSimpleLetBody