Files
affaan-m--everything-claude…/docs/zh-CN/rules/common/coding-style.md
T
wehub-resource-sync d48cda4081
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Failing after 17m13s
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Failing after 18m42s
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Failing after 15m0s
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Failing after 49m44s
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Failing after 51m55s
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Failing after 21m57s
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Failing after 37m39s
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Failing after 34m7s
CI / Validate Components (push) Failing after 37m15s
CI / Python Tests (push) Failing after 10m1s
CI / Security Scan (push) Failing after 10m1s
CI / Lint (push) Failing after 17m12s
CI / Coverage (push) Failing after 20m19s
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:55 +08:00

53 lines
1.4 KiB
Markdown

# 编码风格
## 不可变性(关键)
始终创建新对象,绝不改变现有对象:
```
// 伪代码
WRONG: modify(original, field, value) → 原地修改 original
CORRECT: update(original, field, value) → 返回包含更改的新副本
```
理由:不可变数据可以防止隐藏的副作用,使调试更容易,并支持安全的并发。
## 文件组织
多个小文件 > 少数大文件:
* 高内聚,低耦合
* 通常 200-400 行,最多 800 行
* 从大型模块中提取实用工具
* 按功能/领域组织,而不是按类型组织
## 错误处理
始终全面处理错误:
* 在每个层级明确处理错误
* 在面向用户的代码中提供用户友好的错误消息
* 在服务器端记录详细的错误上下文
* 绝不默默地忽略错误
## 输入验证
始终在系统边界处进行验证:
* 在处理前验证所有用户输入
* 在可用时使用基于模式的验证
* 快速失败并提供清晰的错误消息
* 绝不信任外部数据(API 响应、用户输入、文件内容)
## 代码质量检查清单
在标记工作完成之前:
* \[ ] 代码可读且命名良好
* \[ ] 函数短小(<50 行)
* \[ ] 文件专注(<800 行)
* \[ ] 没有深度嵌套(>4 层)
* \[ ] 正确的错误处理
* \[ ] 没有硬编码的值(使用常量或配置)
* \[ ] 没有突变(使用不可变模式)