-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort case branches to match Msg constructor ordering (only in update functions?) #823
Comments
My initial thought is that this is probably a bit beyond the scope of elm-format, as I'm a bit more hesitant to move blocks of code around than I am about the existing features of sorting imports and However, I'm open to further discussion. Also, FYI, there appears to be an existing elm-review rule that implements this https://package.elm-lang.org/packages/SiriusStarr/elm-review-no-unsorted/1.1.4/NoUnsortedCases/ so you could try that out and see if it either already solves your problem, or use it to learn a bit more about the details of how this should best behave. |
I agree that this is probably not best suited for Limiting this to functions named |
Yep, this is exactly what |
In my day-to-day writing Elm code, I can only think of one significant place where I don't have autoformatting today, but wish I had: specifying the order of my
Msg
constructors in myupdate
functions. That is, if myupdate
function looks like this:then I know that the
A,B,C
ordering is something I've defined somewhere.This usually comes up when I want to add new constructors to an existing
Msg
type. Often those new constructors relate to some existing messages, so I probably want to group them. The most natural place to do so, I find, is with the type definition itself. So although a type like:looks fine, and it's easy to keep
update
using the same ordering, it becomes more annoying to keep them in sync when the type has morphed intoand it would be really nice if there was a way to just keep
update
in sync with an ordering like this. Some caveats though:Msg
types and theupdate
function, and not in general for all custom types everywhere.Of course, those two points can make it tricky to unite this feature with
elm-format
, because it eschews configuration and special cases.On the other hand,
elm-format
already has this feature for a different kind of ordering: formatting exports as specified in module docs. So maybe there is room for something similar forMsg
andupdate
? There's lots of room for bikeshedding here, so I won't make concrete proposals for how it should look before testing if this is something anyone besides me would be interested in 😊The text was updated successfully, but these errors were encountered: