avh4 / elm-format

elm-format formats Elm source code according to a standard set of rules based on the official Elm Style Guide
BSD 3-Clause "New" or "Revised" License
1.31k stars 145 forks source link

Formatting produces invalid code when comment is in pattern of a case expression #824

Open jfmengels opened 1 month ago

jfmengels commented 1 month ago

When introducing a comment in a pattern in a case expression, elm-format will reformat it like the following:

value =
    case x of
        A
            -- comment
            ()
        ->
            1

        B
        -- comment
        ->
            1

Here, both branches are considered to be a syntax error. The -> needs to be indented by at least one space (or move to after the () in the first pattern). (more complete example: https://ellie-app.com/rHrcvrMP88Ha1)

avh4 commented 1 month ago

Ah thanks! I think that's been in there for at least 2 years before anyone noticed it :laughing: This is something https://github.com/avh4/elm-format/issues/36 would have caught, but it's sadly been too much of a mess to get implemented easily.

I can probably get to this over the summer. Also PR is welcome.