truqu/elm-review-noredundantconcat

Provides an elm-review rule to prohibit redundant usage of `++`


Keywords
elm, elm-review, lint
License
BSD-3-Clause
Install
elm-package install truqu/elm-review-noredundantconcat 1.0.1

Documentation

elm-review-noredundantconcat

Helps with preventing redundant usage of concatenation. Expressions like [ a ] ++ b can be rewritten as a :: b, and expressions like [ a ] ++ [ b ] could be simply [ a, b ].

Configuration

module ReviewConfig exposing (config)

import NoRedundantConcat
import Review.Rule exposing (Rule)

config : List Rule
config =
    [ NoRedundantConcat.rule
    ]

Currently covered

  • Concatenating list literals with ++ ([ foo ] ++ [ bar ] -> [ foo, bar ])
  • Concatenating a list literal with some other value ([ foo ] ++ bar -> foo :: bar)
  • Using List.concat with list literals (List.concat [ [ foo ], [ bar ] ] -> [ foo, bar ])
  • Using ++ with String literals ("foo" ++ "bar" -> "foobar")

Future work

  • Using List.append with list literals
  • Using String.append with string literals
  • Using String.concat with string literals
  • Using String.join "" over String.concat

These all follow a common pattern of making the concatenation of literals more complex than it has to be.