elixir-best-practices
Skill1 starsChanged 3 months agoApache-2.0View on GitHub
Elixir coding standards and best practices. Use when writing, reviewing, or refactoring Elixir code to ensure idiomatic patterns, proper error handling, and Phoenix conventions.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- largelanguageplatform/agent-skillstheir own version, first seen Mar 28, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- largelanguageplatform/agent-skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository13 other files it gives its agents.
- humanizer/AGENTS.mdAGENTS.md
- aaif-notebooklm-syncSkill
- asciinema-explainer-walkthroughsSkill
- cuj-screenshotsSkill
- developer-trends-intelSkill
- diagram-designSkill
- engineering-disciplineSkill
- humanizerSkill
- intent-refinementSkill
- manim-video-qualitySkill
- opm-trackingSkill
- storybookSkill
- ui-developerSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
20 rules. About 0 are common, 2 are distinctive, and 18 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
18
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 50
Use with for sequential operations that may fail.
- Very specific: line 70
Do NOT add a complex else block to with.
- Very specific: line 74
Use the pipe |> for data transformation chains.
- Very specific: line 89
Every public function gets a @doc with a doctest.
- Very specific: line 108
Use @moduledoc on every module.
- Very specific: line 159
Use GenServer for stateful processes, not Agent (Agent is for trivial state)
- Very specific: line 160
Prefer Task for one-off async work
- Very specific: line 161
Use Supervisor trees — let processes crash and restart
- Distinctive: line 162
Never catch exits in production code — let the supervisor handle it
- Very specific: line 163
Use Registry for dynamic process lookup, not named processes
- Very specific: line 170
Use Ecto.Multi for transactional operations
- Very specific: line 177
Use Mox for behavior-based mocking, not module replacement
- Very specific: line 179
Use setup blocks for shared fixtures, not helper functions in the test body
- Very specific: line 183
Never use String.to_atom/1 with user input (atom table exhaustion)
- Very specific: line 184
Never use apply/3 when you can use pattern matching
- Very specific: line 185
Never ignore warnings — treat warnings as errors (mix compile --warnings-as-errors)
- Very specific: line 186
Never use Enum.each when you need the result — use Enum.map
- Distinctive: line 187
Never put logic in templates — extract to functions or components
- Very specific: line 188
Never use bare try/rescue — use {:ok, _} / {:error, _} tuples
- Very specific: line 189
Never use is_list/1 to check for keyword lists — use Keyword.keyword?/1
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Elixir SWE Agent Instructions
You are a senior Elixir engineer. Write idiomatic, functional Elixir that leverages the language's strengths. Follow these principles strictly.
Pattern Matching Over Conditionals
if/else is a code smell. Use pattern matching, case, multi-clause functions, and guards instead.
# BAD
def process(user) do
if user.role == :admin do
admin_action(user)
else
regular_action(user)
end
end
# GOOD
def process(%{role: :admin} = user), do: admin_action(user)
def process(user), do: regular_action(user)cond is acceptable for complex boolean chains. if/else is acceptable when branching on a boolean value (per Credo's style rules) — use it for true/false checks rather than forcing pattern matching. if without else is fine for simple nil/truthy guards.
# ACCEPTABLE — boolean check, if/else is idiomatic here
if admin?(user) do
grant_access(user)
else
deny_access(user)
end
# STILL BAD — structural matching shoved into if/else
if user.role == :admin do
admin_action(user)
else
regular_action(user)
end
# Use multi-clause functions or case for structural matchesWith for Happy-Path Pipelines
Use with for sequential operations that may fail. Keep the else clause minimal or omit it entirely by letting the non-matching value pass through.
# BAD — nested case
case fetch_user(id) do
{:ok, user} ->
case authorize(user) do
:ok -> do_thing(user)
error -> error
end
error -> error
end
# GOOD
with {:ok, user} <- fetch_user(id),
:ok <- authorize(user) do
do_thing(user)
endDo NOT add a complex else block to with. If you need to handle multiple error types, pattern match in the caller or use a separate function.
Pipe Operator
Use the pipe |> for data transformation chains. The subject flows through. Do NOT pipe into functions where the data isn't the first argument without wrapping.
# GOOD
data
|> parse()
|> validate()
|> persist()
# BAD — pipe into side-effects or multi-arg functions awkwardly
data |> IO.inspect() |> Map.put(map, :key) # confusingDocumentation and Doctests
Every public function gets a @doc with a doctest. The doctest IS the unit test for the happy path. Write it first.
@doc """
Calculates the total price including tax.
## Examples
iex> calculate_total(100, 0.1)
110.0
iex> calculate_total(0, 0.1)
0.0
"""
def calculate_total(price, tax_rate) do
price * (1 + tax_rate)
endUse @moduledoc on every module. Use @typedoc for public types. No module without a moduledoc.
Structs and Types
Define structs with @enforce_keys for required fields. Always define a @type t() for your structs.
defmodule MyApp.User do
@moduledoc "A registered user."
@enforce_keys [:id, :email]
defstruct [:id, :email, :name, role: :user]
@type t :: %__MODULE__{
id: String.t(),
email: String.t(),
name: String.t() | nil,
role: :user | :admin
}
endError Handling
Return {:ok, value} / {:error, reason} tuples. Never raise for expected failures. Reserve raise and ! functions for programmer errors.
# GOOD — tuple returns
def fetch_user(id) do
case Repo.get(User, id) do
nil -> {:error, :not_found}
user -> {:ok, user}
end
end
# BAD — raising for expected cases
def fetch_user!(id) do
Repo.get(User, id) || raise "not found"
endNaming
- Modules:
PascalCase, organized by domain (MyApp.Accounts.User) - Functions:
snake_case, verb-first for actions (create_user,validate_email) - Predicates: end with
?(valid?,admin?) - Bang functions: end with
!only for functions that raise (create_user!) - Private helpers: prefix with
_only if unused args; usedefpfor private functions
Process Design
- Use
GenServerfor stateful processes, notAgent(Agent is for trivial state) - Prefer
Taskfor one-off async work - Use
Supervisortrees — let processes crash and restart - Never catch exits in production code — let the supervisor handle it
- Use
Registryfor dynamic process lookup, not named processes
Phoenix Conventions
- Thin controllers — delegate to context modules
- Context modules (
Accounts,Billing) own the business logic - Changesets validate at the boundary — never trust input
- Use
Ecto.Multifor transactional operations - LiveView: keep assigns minimal, push computation to the context
Testing
- Doctests for public API happy paths
ExUnittests for edge cases and error paths- Use
Moxfor behavior-based mocking, not module replacement - Async tests by default (
async: true) unless they share state - Use
setupblocks for shared fixtures, not helper functions in the test body
Things to Never Do
- Never use
String.to_atom/1with user input (atom table exhaustion) - Never use
apply/3when you can use pattern matching - Never ignore warnings — treat warnings as errors (
mix compile --warnings-as-errors) - Never use
Enum.eachwhen you need the result — useEnum.map - Never put logic in templates — extract to functions or components
- Never use bare
try/rescue— use{:ok, _} / {:error, _}tuples - Never use
is_list/1to check for keyword lists — useKeyword.keyword?/1
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

