Elixir Code Review
Quick Reference
references/pattern-matching.md |
| GenServer, Supervisor, Application |
references/otp-basics.md |
| @moduledoc, @doc, @spec, doctests |
references/documentation.md |
Review Checklist
Code Style
- - [ ] Module names are CamelCase, function names are snake_case
- [ ] Pipe chains start with raw data, not function calls
- [ ] Private functions grouped after public functions
- [ ] No unnecessary parentheses in function calls without arguments
Pattern Matching
- - [ ] Functions use pattern matching over conditionals where appropriate
- [ ] With clauses have else handling for error cases
- [ ] Guards used instead of runtime checks where possible
- [ ] Destructuring used in function heads, not body
OTP Basics
- - [ ] GenServers use handle_continue for expensive init work
- [ ] Supervisors use appropriate restart strategies
- [ ] No blocking calls in GenServer callbacks
- [ ] Proper use of call vs cast (sync vs async)
Documentation
- - [ ] All public functions have @doc and @spec
- [ ] Modules have @moduledoc describing purpose
- [ ] Doctests for pure functions where appropriate
- [ ] No @doc false on genuinely public functions
Security
- - [ ] No
String.to_atom/1 on user input (use to_existing_atom/1) - [ ] No
Code.eval_string/1 on untrusted input - [ ] No
:erlang.binary_to_term/1 without :safe option
Valid Patterns (Do NOT Flag)
- - Empty function clause for pattern match -
def foo(nil), do: nil is valid guard - Using
|> with single transformation - Readability choice, not wrong @doc false on callback implementations - Callbacks documented at behaviour level- Private functions without @spec - @spec optional for internals
- Using
Kernel.apply/3 - Valid for dynamic dispatch with known module/function
Context-Sensitive Rules
| Issue | Flag ONLY IF |
|---|
| Missing @spec | Function is public AND exported |
| Generic rescue |
Specific exception types available |
| Nested case/cond | More than 2 levels deep |
When to Load References
- - Reviewing module/function naming → code-style.md
- Reviewing with/case/cond statements → pattern-matching.md
- Reviewing GenServer/Supervisor code → otp-basics.md
- Reviewing @doc/@moduledoc → documentation.md
Before Submitting Findings
Load and follow review-verification-protocol before reporting any issue.
Elixir 代码审查
快速参考
references/pattern-matching.md |
| GenServer、Supervisor、Application |
references/otp-basics.md |
| @moduledoc、@doc、@spec、doctests |
references/documentation.md |
审查清单
代码风格
- - [ ] 模块名使用大驼峰命名,函数名使用蛇形命名
- [ ] 管道链以原始数据开头,而非函数调用
- [ ] 私有函数分组在公有函数之后
- [ ] 无参数函数调用中不使用不必要的括号
模式匹配
- - [ ] 函数在适当情况下使用模式匹配而非条件判断
- [ ] With子句包含错误情况的else处理
- [ ] 尽可能使用守卫而非运行时检查
- [ ] 解构在函数头部而非函数体内使用
OTP基础
- - [ ] GenServers使用handle_continue处理耗时的初始化工作
- [ ] Supervisors使用适当的重启策略
- [ ] GenServer回调中无阻塞调用
- [ ] 正确使用call与cast(同步与异步)
文档
- - [ ] 所有公有函数包含@doc和@spec
- [ ] 模块包含描述其用途的@moduledoc
- [ ] 纯函数在适当情况下包含doctests
- [ ] 真正公有函数不使用@doc false
安全性
- - [ ] 不对用户输入使用String.toatom/1(使用toexistingatom/1)
- [ ] 不对不可信输入使用Code.evalstring/1
- [ ] 不使用不带:safe选项的:erlang.binarytoterm/1
有效模式(请勿标记)
- - 用于模式匹配的空函数子句 - def foo(nil), do: nil 是有效的守卫
- 对单一转换使用|> - 可读性选择,并非错误
- 回调实现上的@doc false - 回调在行为层面已记录文档
- 无@spec的私有函数 - 内部函数@spec为可选
- 使用Kernel.apply/3 - 对已知模块/函数进行动态分派有效
上下文敏感规则
| 问题 | 仅在以下情况标记 |
|---|
| 缺少@spec | 函数是公有的且已导出 |
| 通用rescue |
存在特定异常类型 |
| 嵌套case/cond | 超过2层深度 |
何时加载参考文档
- - 审查模块/函数命名 → code-style.md
- 审查with/case/cond语句 → pattern-matching.md
- 审查GenServer/Supervisor代码 → otp-basics.md
- 审查@doc/@moduledoc → documentation.md
提交发现前
在报告任何问题前,请加载并遵循审查验证协议。