elixir-code-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseElixir Code Review
Elixir代码评审
Quick Reference
快速参考
| Issue Type | Reference |
|---|---|
| Naming, formatting, module structure | references/code-style.md |
| With clauses, guards, destructuring | references/pattern-matching.md |
| GenServer, Supervisor, Application | references/otp-basics.md |
| @moduledoc, @doc, @spec, doctests | references/documentation.md |
| 问题类型 | 参考资料 |
|---|---|
| 命名、格式、模块结构 | references/code-style.md |
| With子句、守卫、解构 | references/pattern-matching.md |
| GenServer、Supervisor、Application | references/otp-basics.md |
| @moduledoc、@doc、@spec、文档测试 | 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
- 模块名称采用驼峰式(CamelCase),函数名称采用蛇形命名(snake_case)
- 管道链(|>)以原始数据开头,而非函数调用
- 私有函数分组在公共函数之后
- 无参数的函数调用中没有多余的括号
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
- 函数在合适的场景下使用模式匹配而非条件判断
- With子句包含错误情况的else处理
- 尽可能使用守卫而非运行时检查
- 在函数头中使用解构,而非函数体
OTP Basics
OTP基础
- 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)
- GenServers使用handle_continue处理耗时的初始化工作
- Supervisors使用合适的重启策略
- GenServer回调中没有阻塞调用
- 正确区分call与cast(同步 vs 异步)的使用
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
- 所有公共函数都有@doc和@spec
- 模块包含描述其用途的@moduledoc
- 纯函数在合适的场景下添加文档测试
- 真正的公共函数不使用@doc false
Security
安全
- No on user input (use
String.to_atom/1)to_existing_atom/1 - No on untrusted input
Code.eval_string/1 - No without
:erlang.binary_to_term/1option:safe
- 不对用户输入使用(改用
String.to_atom/1)to_existing_atom/1 - 不对不可信输入使用
Code.eval_string/1 - 不使用不带选项的
:safe:erlang.binary_to_term/1
Valid Patterns (Do NOT Flag)
有效模式(请勿标记)
- Empty function clause for pattern match - is valid guard
def foo(nil), do: nil - Using with single transformation - Readability choice, not wrong
|> - on callback implementations - Callbacks documented at behaviour level
@doc false - Private functions without @spec - @spec optional for internals
- Using - Valid for dynamic dispatch with known module/function
Kernel.apply/3
- 用于模式匹配的空函数子句 - 是有效的守卫
def foo(nil), do: nil - 对单一转换使用- 可读性选择,并非错误
|> - 回调实现上的- 回调在行为层面已做文档说明
@doc false - 没有@spec的私有函数 - @spec对内部函数是可选的
- 使用- 对已知模块/函数进行动态调度是有效的
Kernel.apply/3
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 |
| 问题 | 仅在以下情况标记 |
|---|---|
| 缺少@spec | 函数是公共且已导出的 |
| 通用rescue | 存在特定异常类型可选 |
| 嵌套case/cond | 超过2层深度 |
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
- 评审模块/函数命名 → code-style.md
- 评审with/case/cond语句 → pattern-matching.md
- 评审GenServer/Supervisor代码 → otp-basics.md
- 评审@doc/@moduledoc → documentation.md
Before Submitting Findings
提交发现前的准备
Load and follow review-verification-protocol before reporting any issue.
在报告任何问题之前,请加载并遵循评审验证协议。