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

MultipleAppendToConcat

Rule: Replace multiple ++ in sequence with concat.

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

  • changing indentation messes up multi-line strings
  • case..of cases and let declarations are indentation sensitive, so adding for example a comma in front of the first line can lead to compiler errors

elm-format will safely prettify it anyway

= ApplyList
| PipeRightList
| PipeLeftList

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

  • ApplyList: List.concat [ ... ]
  • PipeRightList: [ ... ] |> List.concat
  • PipeLeftList: List.concat <| [ ... ]