clojure-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClojure Code Review Skill
Clojure代码评审技能
@./../_shared/clojure-style-guide.md
@./../_shared/clojure-commands.md
@./../_shared/clojure-style-guide.md
@./../_shared/clojure-commands.md
Review guidelines
评审指南
What to flag:
- Check compliance with the Metabase Clojure style guide (included above)
- If exists in the working directory, also check compliance with the community Clojure style guide
CLOJURE_STYLE_GUIDE.adoc - Flag all style guide violations
What NOT to post:
- Do not post comments congratulating someone for trivial changes or for following style guidelines
- Do not post comments confirming things "look good" or telling them they did something correctly
- Only post comments about style violations or potential issues
Example bad code review comments to avoid:
This TODO comment is properly formatted with author and date - nice work!
Good addition of limit 1 to the query - this makes the test more efficient without changing its behavior.
The kondo ignore comment is appropriately placed here
Test name properly ends with -test as required by the style guide.
Special cases:
- Do not post comments about missing parentheses (these will be caught by the linter)
需要标记的内容:
- 检查是否符合Metabase Clojure风格指南(已包含在上方)
- 如果工作目录中存在,同时检查是否符合社区Clojure风格指南
CLOJURE_STYLE_GUIDE.adoc - 标记所有风格指南违规情况
请勿发布的内容:
- 请勿发布对微小变更或遵循风格指南的表扬评论
- 请勿发布“看起来不错”或确认对方操作正确的评论
- 仅发布关于风格违规或潜在问题的评论
需避免的错误代码评审评论示例:
这个TODO注释的格式正确,包含了作者和日期 - 做得好!
在查询中添加limit 1很棒 - 这让测试更高效且不改变其行为。
kondo忽略注释的位置很合适
测试名称正确以-test结尾,符合风格指南要求。
特殊情况:
- 请勿发布关于缺失括号的评论(这些会被检查器捕获)
Quick review checklist
快速评审清单
Use this to scan through changes efficiently:
使用此清单高效扫描代码变更:
Naming
命名
- Descriptive names (no ,
tbl)zs' - Pure functions named as nouns describing their return value
- for all variables and functions
kebab-case - Side-effect functions end with
! - No namespace-alias repetition in function names
- 使用描述性名称(避免、
tbl这类缩写)zs' - 纯函数使用描述返回值的名词命名
- 所有变量和函数使用命名法
kebab-case - 有副作用的函数以结尾
! - 函数名称中不要重复命名空间别名
Documentation
文档
- Public vars in or
srchave useful docstringsenterprise/backend/src - Docstrings use Markdown conventions
- References use not backticks
[[other-var]] - comments include author and date:
TODO;; TODO (Name 2025-01-01) -- description
- 或
src中的公共变量需包含实用的文档字符串enterprise/backend/src - 文档字符串使用Markdown规范
- 引用使用而非反引号
[[other-var]] - 注释需包含作者和日期:
TODO;; TODO (Name 2025-01-01) -- 描述内容
Code Organization
代码组织
- Everything unless used elsewhere
^:private - No when avoidable (public functions near end)
declare - Functions under 20 lines when possible
- No blank, non-comment lines within definition forms (except pairwise constructs in /
let)cond - Lines ≤ 120 characters
- 除非在其他地方使用,否则所有内容标记为
^:private - 尽可能避免使用(公共函数放在末尾)
declare - 函数代码尽可能控制在20行以内
- 定义形式内不要有空的非注释行(/
let中的成对结构除外)cond - 每行长度≤120字符
Tests
测试
- Separate forms for distinct test cases
deftest - Pure tests marked
^:parallel - Test names end in or
-test-test-<number>
- 不同的测试用例使用独立的形式
deftest - 纯测试标记为
^:parallel - 测试名称以或
-test结尾-test-<数字>
Modules
模块
- Correct module patterns (OSS: , EE:
metabase.<module>.*)metabase-enterprise.<module>.* - API endpoints in namespaces
<module>.api - Public API in with Potemkin
<module>.core - No cheating module linters with
:clj-kondo/ignore [:metabase/modules]
- 使用正确的模块模式(开源版:,企业版:
metabase.<module>.*)metabase-enterprise.<module>.* - API端点放在命名空间中
<module>.api - 公共API放在中并使用Potemkin
<module>.core - 不要使用规避模块检查器
:clj-kondo/ignore [:metabase/modules]
REST API
REST API
- Response schemas present ()
:- <schema> - Query params use kebab-case, bodies use
snake_case - Routes use singular nouns (e.g., )
/api/dashboard/:id - has no side effects (except analytics)
GET - Malli schemas detailed and complete
- All new endpoints have tests
- 存在响应模式()
:- <schema> - 查询参数使用kebab-case,请求体使用
snake_case - 路由使用单数名词(例如:)
/api/dashboard/:id - 请求无副作用(分析统计除外)
GET - Malli模式详细且完整
- 所有新端点都有对应的测试
MBQL
MBQL
- No raw MBQL manipulation outside ,
lib, orlib-bemodulesquery-processor - Uses Lib and MBQL 5, not legacy MBQL
- 除、
lib或lib-be模块外,不要直接操作原始MBQLquery-processor - 使用Lib和MBQL 5,而非旧版MBQL
Database
数据库
- Model and table names are singular nouns
- Uses instead of selecting full rows for one column
t2/select-one-fn - Logic in Toucan methods, not helper functions
- 模型和表名使用单数名词
- 使用替代查询整行来获取单个列的值
t2/select-one-fn - 逻辑放在Toucan方法中,而非辅助函数
Drivers
驱动
- New multimethods documented in
docs/developers-guide/driver-changelog.md - Passes argument to other driver methods (no hardcoded driver names)
driver - Minimal logic in
read-column-thunk
- 新的多方法需在中记录
docs/developers-guide/driver-changelog.md - 向其他驱动方法传递参数(不要硬编码驱动名称)
driver - 中的逻辑尽可能精简
read-column-thunk
Miscellaneous
其他
- Example data is bird-themed when possible
- Kondo linter suppressions use proper format (not keyword form)
#_:clj-kondo/ignore
- 示例数据尽可能使用鸟类主题
- Kondo检查器抑制规则使用正确格式(不要使用关键字形式)
#_:clj-kondo/ignore
Pattern matching table
模式匹配对照表
Quick scan for common issues:
| Pattern | Issue |
|---|---|
| Pure functions should be nouns: |
| Missing |
| Should use kebab-case |
| Public var without docstring | Add docstring explaining purpose |
| Missing author/date: |
| Should be |
| Function > 20 lines | Consider breaking up into smaller functions |
| Use singular: |
Query params with | Use kebab-case for query params |
| New API endpoint without tests | Add tests for the endpoint |
快速扫描常见问题:
| 模式 | 问题说明 |
|---|---|
| 纯函数应使用描述返回值的名词命名:建议将 |
| 有副作用的函数缺少 |
| 应使用kebab-case命名法 |
| 公共变量无文档字符串 | 添加说明其用途、输入和输出的文档字符串 |
| 缺少作者/日期:应改为 |
| 应标记为 |
| 函数代码超过20行 | 考虑拆分为更小的函数 |
| 使用单数形式: |
查询参数使用 | 查询参数应使用kebab-case:将 |
| 新API端点无测试 | 为此端点添加测试 |
Feedback format examples
反馈格式示例
For style violations:
This pure function should be named as a noun describing its return value. Considerinstead ofuser.get-user
For missing documentation:
This public var needs a docstring explaining its purpose, inputs, and outputs.
For organization issues:
This function is only used in this namespace, so it should be marked.^:private
For API conventions:
Query parameters should use kebab-case. Changetouser_id.user-id
针对风格违规:
此纯函数应使用描述返回值的名词命名。建议将改为get-user。user
针对缺失文档:
此公共变量需要添加说明其用途、输入和输出的文档字符串。
针对代码组织问题:
此函数仅在当前命名空间中使用,因此应标记为。^:private
针对API规范问题:
查询参数应使用kebab-case。请将改为user_id。user-id