elm-review rule: forbid record type alias
constructors.
Read more about the why in no-record-type-alias-constructor-function
.
- 🔧
NoRecordAliasConstructor
: detect & fix constructor usages - 🔧
NoRecordAliasWithConstructor
: detect record aliases that have a constructor & fix by usingRecordWithoutConstructorFunction
In contrast to lxierita's no-typealias-constructor-call, this rule also reports constructors that aren't called (for example in Json.Decode.mapN
functions). ↑ all differences
type alias User =
{ name : String, age : Int }
User "Balsa" 42
will be marked as error and automatically fixed:
{ name = "Balsa", age = 42 }
The same goes for cases where no arguments are applied:
map2 User
(field "name" string)
(field "age" int)
fixed
map2 (\name age -> { name = name, age = age })
(field "name" string)
(field "age" int)
lxierita/no-typealias-constructor-call...
- ..only reports record alias constructors that are called directly
aren't reported for example
(User <| "Ann") <| 18 (identity User) "Bill" 42 User |> (\user -> user "Cem" 66)
- ..doesn't provide automatic fixes → refactoring is inconvenient
- ..only looks for type aliases in the same module. This package finds every used record alias
type alias User =
{ name : String, age : Int }
will be marked as error and automatically fixed:
import RecordWithoutConstructorFunction exposing (RecordWithoutConstructorFunction)
type alias User =
RecordWithoutConstructorFunction
{ name : String, age : Int }
disallowing constructor functions from being created.
elm-review --template lue-bird/elm-record-alias-constructor/example
After adding elm-review to your project, import this rule from
your ReviewConfig.elm
file and add it to the config. E.g.:
import NoRecordAliasConstructor
import NoRecordAliasWithConstructor
import Review.Rule exposing (Rule)
config : List Rule
config =
[ NoRecordAliasConstructor.rule
, NoRecordAliasWithConstructor.rule
]