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 ]
++ dfixed 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 fixelm-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 etcThis 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
...appendable and infix operatorsString.concat and List.concat take concrete types and don't have the "magic-ness" of constrained type variables, operator precedence etc.
elm-review --template lue-bird/elm-review-multiple-append-to-concat/exampleIf you like what it does, install it to your review/ project and
module ReviewConfig exposing (config)
import MultipleAppendToConcat
import Review.Rule exposing (Rule)
config : List Rule
config =
[ MultipleAppendToConcat.rule MultipleAppendToConcat.ApplyList
]