NoMissingTypeConstructor elm-review rule fix

I added a fix to the elm-review NoMissingTypeConstructor rule. I’m looking for folks to try this and provide feedback on how it works for you.

elm-review --template Arkham/elm-review-no-missing-type-constructor/example --fix

Example

Before fix

module Fruit exposing (Fruit, all)

type Fruit
    = Apple
    | Banana
    | Kiwi
    | Pineapple

all : List Fruit
all =
    [ Banana
    , Apple
    ]

After fix

module Fruit exposing (Fruit, all)

type Fruit
    = Apple
    | Banana
    | Kiwi
    | Pineapple

all : List Fruit
all =
    [ Banana
    , Apple
    , Kiwi
    , Pineapple
    ]

The missing type constructors Kiwi and Pineapple were added in alphabetical order.

Feedback request

Is this fix acceptable? Do you rely on the order?

When I use an all value I usually have toString : Fruit -> String that returns the display name. Then I sort by that:

Fruit.all
    |> List.map Fruit.toString
    |> List.sort

Using this technique, the order of the variants in all is irrelevant.

Maybe you have a different concern. Or maybe this fix is just fine. Please let me know your thoughts.

3 Likes

Thanks! We were just looking for this rule a few days ago.

1 Like

When the type constructor accepts parameters the rule checker= considers them as missing. Consider this example:

type Route 
    = Root
    | Home
    | UserDetails Int

allRoutes : Int -> List Route
allRoutes userId =
    [ Root
    , Home
    , UserDetails userId
    ]

In this example, it complaints that UserDetails constructor is not present. It would be great that it realized that there is a UserDetailts. Does it look consistent with what you want to achieve?

Good question! From this GitHub issue I believe the intention is for the rule to only be useful for simple variants without arguments.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.