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

NOTE: the latest version is 1.0.2

elm-review-multiple-append-to-concat

Provides the elm-review rule 🔧MultipleAppendToConcat that replaces multiple ++ in sequence with concat, like

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

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
  • It is highly, highly recommended to use elm-review-simplify alongside which simplifies
    • [ a, b ] ++ [ c, d ] to [ a, b, c, d ]
    • [] ++ [ b, c ] to [ b, c ]
    • [ a ] ++ b ++ c to a :: b ++ c etc

why

it's more readable

This is somewhat subjective. Make sure everyone thinks the same before enabling the rule.

someDeclaration =
    let
        combinedList =
            (a
                ++ ([ b, c ]
                        |> List.map .name
                   )
                ++ d
            )
                |> String.join ", "
    in
    ...

vs

someDeclaration =
    let
        combinedList =
            [ a
            , [ b, c ]
                |> List.map .name
            , d
            ]
                |> List.concat
                |> String.join ", "
    in
    ...

less appendable and infix operators

String.concat and List.concat take concrete types and don't have the "magic-ness" of constrained type variables, operator precedence etc.

try it out

elm-review --template lue-bird/elm-review-multiple-append-to-concat/example

If you like what it does, install it to your review/ project and

configure it

module ReviewConfig exposing (config)

import MultipleAppendToConcat
import Review.Rule exposing (Rule)

config : List Rule
config =
    [ MultipleAppendToConcat.rule MultipleAppendToConcat.ApplyList
    ]