Provides elm-review rules to point out type aliases to simple primitive types (String, Char, Bool, Int, Float, ()).
Type Aliases that point to simple primitive types can give a false sense of security because these type aliases provide a label that you could use in unintended ways without getting compiler feedback. For example, if you have two type definitions
type alias UserId = String
type alias ShippingAddress = StringThen you could miss out on helpful compiler feedback in the following scenarios:
UserId on a value which actually represents a shipping address, orString on a value which is actually a UserIdShippingAddressShippingAddress and UserId, but since they're just Strings as far as the compiler is concerned, there is no error to let you know.All of these cases could provide you with more helpful compiler feedback if you use custom types like
type UserId = UserId Stringand
type ShippingAddress = ShippingAddress Stringinstead.
See a more in-depth discussion in the Elm Radio episode about Primitive Obsession.
NoPrimitiveTypeAlias - Reports type aliases for simple primitive types.module ReviewConfig exposing (config)
import NoPrimitiveTypeAlias
import Review.Rule exposing (Rule)
config : List Rule
config =
[ NoPrimitiveTypeAlias.rule
]You can try the example configuration above out by running the following command:
elm-review --template dillonkearns/elm-review-no-primitive-type-alias/preview