delphi-code-review
@delphicleancode · 收录于 1 周前
Delphi code review checklist — quality, security, performance, SOLID, memory
适合你,如果需要在 Delphi 项目中做代码审查
/ 下载安装
用别的 agent?下载 .zip 解压,把文件夹放进它的技能目录
Claude Code
~/.claude/skills/(项目级 .claude/skills/)Codex CLI
~/.codex/skills/Cursor自动读取上面两处目录
其他工具见其文档的「skills」目录;两个下载是同一份文件,只是名字不同
/ 通过 npx 安装 校验哈希
npx oh-my-skill add delphicleancode/delphi-spec-kit/delphi-code-review/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- delphicleancode/delphi-spec-kit/delphi-code-review/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify delphicleancode/delphi-spec-kit/delphi-code-review安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
43GitHub stars
~789上下文体积 · 单文件
镜像托管
怎么用
技能原文 SKILL.md
Delphi Code Review — Skill
Quick Checklist
Corretude
- [ ] Code does what it's supposed to do
- [ ] Edge cases handled (nil, empty list, zero value)
- [ ] Error handling implemented with specific exceptions
- [ ] No obvious bugs
Security
- [ ] Parameterized SQL queries (without string concatenation)
- [ ] Validated and sanitized input
- [ ] No hardcoded credentials or passwords
- [ ] No SQL injection via
Formator concatenation in queries
Performance
- [ ] No N+1 queries (avoid loop with query inside)
- [ ] No unnecessary loops
- [ ] Large objects released as early as possible
- [ ]
TObjectListwithOwnsObjectsconfigured correctly
Code Quality
- [ ] Self-descriptive names following Pascal Guide
- [ ] DRY — no duplicate code
- [ ] SOLID — principles respected
- [ ] Methods ≤ 20 lines
- [ ] Guard clauses instead of deep nesting
Memory Management
- [ ]
try/finallywithFreefor temporary objects - [ ] Interfaces for automatic reference counting
- [ ]
Assigned()before accessing references that may be nil - [ ] Destructor
Destroywithoverridefreeing owned fields - [ ] No memory leaks in exception paths
Pascal Nomenclature
- [ ] PascalCase for all identifiers
- [ ] Prefix
Tin classes,Iin interfaces,Ein exceptions - [ ] Prefix
Fin private fields,Ain parameters,Lin local variables - [ ] Units:
Projeto.Camada.Dominio.Funcionalidade.pas - [ ] Components: 3-letter prefix (
btn,edt,lbl, etc.)
Tests
- [ ] Unit tests for new code
- [ ] Edge cases tested
- [ ] Readable and maintainable tests
Documentation
- [ ] XMLDoc for public methods and properties
- [ ] Comments in Portuguese when necessary
- [ ] Do not comment self-explanatory code
Anti-Patterns to Flag
//❌ Magic numbers
if ACustomer.Age > 18 then
//✅ Named constants
const MINIMUM_AGE = 18;
if ACustomer.Age > MINIMUM_AGE then
//❌ with statement
with AQuery do begin
SQL.Text := '...';
Open;
end;
//✅ Explicit reference
AQuery.SQL.Text := '...';
AQuery.Open;
//❌ Generic Catch
except
on E: Exception do ShowMessage(E.Message);
//✅ Specific exceptions
except
on E: EFDDBEngineException do
raise EDatabaseException.Create('Falha: ' + E.Message);
//❌ Logic in OnClick
procedure TfrmMain.btnSaveClick(Sender: TObject);
begin
//50 lines of business logic here
end;
//✅ Delegate for Service
procedure TfrmMain.btnSaveClick(Sender: TObject);
begin
FService.SaveCustomer(GetFormData);
end;
// ❌ Memory leak
function GetItems: TStringList;
begin
Result := TStringList.Create;
LoadItems(Result); //if LoadItems throws exception, leak!
end;
//✅ Safe
function GetItems: TStringList;
begin
Result := TStringList.Create;
try
LoadItems(Result);
except
Result.Free;
raise;
end;
end;
Review Comments Guide
🔴 BLOQUEANTE: Memory leak — objeto não liberado em caso de exception 🔴 BLOQUEANTE: SQL injection — query usando concatenação de string 🟡 SUGESTÃO: Extrair método — este bloco tem 35 linhas 🟡 SUGESTÃO: Usar interface em vez de classe concreta (DIP) 🟢 NIT: Renomear variável 'S' para nome descritivo 🟢 NIT: Preferir guard clause a nesting ❓ PERGUNTA: O que acontece se ACustomer for nil aqui? ❓ PERGUNTA: Este objeto é liberado por quem?
Specific SOLID Checklist
| Principle | Check | |-----------|-----------| | SRP | Does class have ONE responsibility? Service does not access data? | | OCP | Do new features add classes, not modify existing ones? | | LSP | Does either implementation of the interface work in place of the other? | | ISP | Doesn't interface have methods that implementers don't use? | | DIP | Constructor takes interfaces, not concrete classes? |
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →
评论
登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。
…