organize-file
Use when reorganizing the whole file (all definitions in that module or test). To reorder only definitions touched on the current branch, use surge/skills/doctor/organize-changes/SKILL.md instead.
Precedence over file conventions
- These ordering rules override local habits and one-off layout in the file (e.g. clustered helpers, private functions near call sites). Do not preserve layout when it conflicts with General rules or Specific rules below.
General rules
- Treat all clauses of the same function name and arity as one unit; within that unit, order clauses alphabetically by the distinguishing atom(s) or parameters.
- Do not reorder clauses when it would change which pattern matches (specificity or catch-all order).
- Keep callback clause groups contiguous (e.g. all
handle_params/3clauses together). - Keep each moved function body unchanged except for location.
- Preserve module structure, comments, spacing, and non-function code.
- Private functions (
defp) always go last, alphabetically by function name.
Specific rules
-
LiveView modules
- Default callback order:
mount/3,handle_params/3,handle_event/3,handle_info/2,handle_async/3, then other handlers, thenrender/1 - Order
handle_event/3clauses alphabetically by event name.
- Default callback order:
-
LiveComponent modules
- Default callback order:
mount/1,update/2,handle_event/3,handle_info/2,handle_async/3, then other handlers, thenrender/1 - Keep callback groups contiguous, especially
update/2andhandle_event/3 - Order
handle_event/3clauses alphabetically by event name.
- Default callback order:
-
Other modules
- Follow General rules: public functions (
def) first, alphabetically by function name; private functions (defp) last. If there are delegates (defdelegate), order them intermixed with the public functions (def)
- Follow General rules: public functions (
-
Test modules
- Apply ordering within each
describeblock (mirror that order when nestingdescribe). - For a given behavior, happy path first, then related error/edge tests immediately after (not interleaved with other features).
- Keep
describe/testgroupings consistent: success scenario first, then its failures/edges in the same cluster.
- Apply ordering within each
Output expectations
- Move functions to their correct positions even when that crosses large regions of the file.
- Respect clause and pattern order per General rules.
- In LiveView and LiveComponent modules, callback lifecycle order wins over alphabetical order among callbacks.
More from jasonharmongit/jh-skills
doctor
Runs pre-PR formatting, checking and testing.
30organize-elixir-functions
Organize functions in a file or across a branch.
30walkthrough-process
Writes a deep markdown walkthrough for code understanding - how a function, module, or process fits into the system. Also supports branch-change walkthroughs when the user explicitly asks about PR/branch diffs.
24solutionize
Plan-only workflow with a human partner; no implementation while this skill governs the turn
22create-skill
>-
21implement-next-phase
Prepare to implement the next pending todo phase from a solutionize sketch plan (frontmatter todos); implementation only after explicit user approval.
8