docs: add code size guidance · openclaw/openclaw@9a60fcf
steipete
·
2026-05-25
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -141,6 +141,15 @@ Skills own workflows; root owns hard policy and routing.
|
141 | 141 | - Calls should be boring: complex decisions happen above; call args/object fields are names, literals, or simple property reads. |
142 | 142 | - Prefer early returns over nested condition pyramids. Split code into gather -> normalize -> decide -> act. |
143 | 143 | - Use named intermediates only for domain meaning or readability; avoid temp-variable soup. |
| 144 | +- Code size matters. Prefer small clear code; maintainability includes not growing LOC without payoff. |
| 145 | +- Refactors should delete about as much local complexity as they add. If LOC grows, the new ownership/API needs to clearly pay for it. |
| 146 | +- Before adding helpers/files, check whether existing code can absorb the behavior with less new surface. |
| 147 | +- Keep APIs narrow: export only current caller needs; keep types/helpers local by default. |
| 148 | +- Return the smallest useful shape. Avoid broad result objects, flags, metadata unless callers use them. |
| 149 | +- Avoid adapter layers that only rename fields. Move real responsibility or leave code local. |
| 150 | +- Inline simple one-use objects/spreads when clearer. Extract only when it removes duplication or hard logic. |
| 151 | +- Tests prove behavior/regressions, not every internal branch. |
| 152 | +- For non-trivial refactors, check `git diff --numstat` before closeout. If LOC grew, trim or explain why. |
144 | 153 | - Dynamic import: no static+dynamic import for same prod module. Use `*.runtime.ts` lazy boundary. After edits: `pnpm build`; check `[INEFFECTIVE_DYNAMIC_IMPORT]`. |
145 | 154 | - Cycles: keep `pnpm check:import-cycles` + architecture/madge green. |
146 | 155 | - Classes: no prototype mixins/mutations. Prefer inheritance/composition. Tests prefer per-instance stubs. |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。