lue-bird / elm-review-multiple-append-to-concat / MultipleAppendToConcat

Rule: Replace multiple ++ in sequence with concat.

rule : ListSupplyStyle -> Review.Rule.Rule

Replaces multiple ++ in sequence with concat in a given ListSupplyStyle.

For example, running MultipleAppendToConcat.rule MultipleAppendToConcat.ApplyList on

combinedString =
    "Your name is "
        ++ (nameParts
                |> String.join " "
           )
        ++ " and your age is "
        ++ (age |> String.fromInt)
        ++ "."

is fixed to

combinedString =
    String.concat
        [ "Your name is "
        , nameParts
            |> String.join " "
        , " and your age is "
        , age |> String.fromInt
        , "."
        ]

and for lists

combinedList =
    a
        ++ [ b, c ]
        ++ d

fixed to

combinedList =
    List.concat
        [ a
        , [ b, c ]
        , d
        ]

elm-review doesn't have type inference, so for values like a ++ b ++ c this rule doesn't provide a fix.

Read the readme for why you would (not) want to enable this rule.

Also don't be surprised when fixes look cursed. The fix keeps all appended operands in their original place. No extra aligning and indentation. This is necessary because

elm-format will safely prettify it anyway


type ListSupplyStyle
    = ApplyList
    | PipeRightList
    | PipeLeftList

In what style will [ ... ] be supplied to List.concat?