Would auto formatting/sorting phoenix liveview/live component callbacks make sense?

I’ve been recently been doing the “vibe coding” thing a lot using cursor and I’m finding that very frequently the models don’t group liveview callbacks appropriately, which results in compiler warning that kills the “vibe”.

For example, it’ll do something like:

def handle_event(...

def handle_info(...

def handle_event(...

Which will result in a compiler warning.

I just wanted to check in with folks, would it be crazy to consider auto sorting liveview callbacks?

I have a really hacky AI written fork of styler here that seems to work okay on my current codebase. If you’re curious about the very few cases that I’ve considered already, please see the tests for liveview here and the tests for liveview components here.

The TLDR is that it basically standardizes the order of callbacks, similar to credo’s StrictModuleLayout. The current liveview order of preference is:

  1. mount/3
  2. handle_params/3
  3. handle_event/3
  4. handle_info/2
  5. handle_async/2
  6. handle_call/3
  7. handle_cast/2
  8. update/2
  9. terminate/2
  10. render/1

And the live component order is:

  1. mount/1
  2. update/2
  3. update_many/1
  4. handle_event/3
  5. handle_async/2
  6. render/1

Does anyone else have interest in this kind of thing?

Edited

I do use rulesets and they don’t work 100% of the time for me which is why I’ve considered this solution for myself.

1 Like