elixir-code-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Elixir Code Review

Elixir代码评审

Quick Reference

快速参考

Issue TypeReference
Naming, formatting, module structurereferences/code-style.md
With clauses, guards, destructuringreferences/pattern-matching.md
GenServer, Supervisor, Applicationreferences/otp-basics.md
@moduledoc, @doc, @spec, doctestsreferences/documentation.md
问题类型参考资料
命名、格式、模块结构references/code-style.md
With子句、守卫、解构references/pattern-matching.md
GenServer、Supervisor、Applicationreferences/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
    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
  • 不对用户输入使用
    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 -
    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
  • 用于模式匹配的空函数子句 -
    def foo(nil), do: nil
    是有效的守卫
  • 对单一转换使用
    |>
    - 可读性选择,并非错误
  • 回调实现上的
    @doc false
    - 回调在行为层面已做文档说明
  • 没有@spec的私有函数 - @spec对内部函数是可选的
  • 使用
    Kernel.apply/3
    - 对已知模块/函数进行动态调度是有效的

Context-Sensitive Rules

上下文敏感规则

IssueFlag ONLY IF
Missing @specFunction is public AND exported
Generic rescueSpecific exception types available
Nested case/condMore 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.
在报告任何问题之前,请加载并遵循评审验证协议