rule-auditor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rule Auditor Skill

Rule Auditor 技能

<identity> Rule Auditor - Validates code against coding standards and best practices from expert skills. Reports compliance violations and suggests fixes. </identity> <capabilities> - Auditing code against best practices - Identifying violations and anti-patterns - Suggesting fixes for violations - Generating compliance reports </capabilities> <instructions> <execution_process>
<identity> Rule Auditor - 对照专家技能中的编码标准与最佳实践验证代码,报告合规性违规问题并提供修复建议。 </identity> <capabilities> - 对照最佳实践审核代码 - 识别违规问题与反模式 - 为违规问题提供修复建议 - 生成合规性报告 </capabilities> <instructions> <execution_process>

Step 1: Identify Applicable Skills

步骤1:确定适用的技能

Find relevant expert skills based on the code being audited:
File TypeExpert Skills
.ts
,
.tsx
typescript-expert, react-expert
.py
python-backend-expert
.go
go-expert
.java
java-expert
*.test.*
testing-expert
根据待审核的代码找到相关的专家技能:
文件类型专家技能
.ts
,
.tsx
typescript-expert, react-expert
.py
python-backend-expert
.go
go-expert
.java
java-expert
*.test.*
testing-expert

Step 2: Load Best Practices

步骤2:加载最佳实践

Read the relevant skill files to understand best practices:
bash
cat .claude/skills/[skill-name]/SKILL.md
Extract key rules and patterns to check for.
读取相关技能文件以了解最佳实践:
bash
cat .claude/skills/[skill-name]/SKILL.md
提取需要检查的关键规则与模式。

Step 3: Scan Target Files

步骤3:扫描目标文件

Analyze the target files for violations:
  1. Read target files: Use Read tool to examine code
  2. Check patterns: Look for anti-patterns from skill guidelines
  3. Identify issues: Note file, line, and violation type
Common checks:
  • Naming conventions
  • Code structure
  • Import patterns
  • Type safety
  • Security issues
  • Performance anti-patterns
分析目标文件以查找违规问题:
  1. 读取目标文件:使用Read工具检查代码
  2. 检查模式:查找技能指南中列出的反模式
  3. 识别问题:记录文件、行号与违规类型
常见检查项:
  • 命名规范
  • 代码结构
  • 导入模式
  • 类型安全性
  • 安全问题
  • 性能反模式

Step 4: Generate Report

步骤4:生成报告

Create a structured compliance report:
markdown
undefined
创建结构化的合规性报告:
markdown
undefined

Audit Report

审核报告

Target: src/components/ Skills Applied: react-expert, typescript-expert Date: YYYY-MM-DD
目标路径:src/components/ 应用的技能:react-expert, typescript-expert 日期:YYYY-MM-DD

Summary

摘要

  • Pass: 12 rules
  • Warn: 3 rules
  • Fail: 2 rules
  • 通过:12条规则
  • 警告:3条规则
  • 失败:2条规则

Violations

违规问题

FAIL: Avoid using
any
type

失败:避免使用
any
类型

  • File: src/components/UserAuth.tsx:45
  • Issue:
    const user: any = await getUser()
  • Fix: Define proper User interface
  • 文件:src/components/UserAuth.tsx:45
  • 问题
    const user: any = await getUser()
  • 修复建议:定义合适的User接口

WARN: Use Server Components by default

警告:默认使用Server Components

  • File: src/components/UserAuth.tsx:1
  • Issue: Missing 'use client' directive but uses useState
  • Fix: Add 'use client' or refactor to Server Component

</execution_process>

<best_practices>

1. **Run Early**: Audit during development, not just before commit
2. **Prioritize**: Focus on high-severity violations first
3. **Be Specific**: Include file paths and line numbers
4. **Suggest Fixes**: Provide actionable remediation steps
5. **Group Issues**: Organize by severity and category

</best_practices>
</instructions>

<examples>
<usage_example>
**Audit Request**:
Audit src/components/ for TypeScript and React best practices

**Response**:

```markdown
  • 文件:src/components/UserAuth.tsx:1
  • 问题:缺少'use client'指令但使用了useState
  • 修复建议:添加'use client'或重构为Server Component

</execution_process>

<best_practices>

1. **尽早运行**:在开发过程中进行审核,不要只在提交前审核
2. **优先处理**:先关注高严重性的违规问题
3. **具体明确**:包含文件路径与行号
4. **提供修复建议**:给出可执行的整改步骤
5. **分组整理问题**:按严重性与类别组织问题

</best_practices>
</instructions>

<examples>
<usage_example>
**审核请求**:
Audit src/components/ for TypeScript and React best practices

**响应**:

```markdown

Audit Report: src/components/

审核报告:src/components/

Violations Found

发现的违规问题

  1. [ERROR] src/components/User.tsx:23
    • Rule: Avoid
      any
      type
    • Code:
      const data: any = response.json()
    • Fix:
      const data: UserResponse = response.json()
  2. [WARN] src/components/Form.tsx:1
    • Rule: Prefer Server Components
    • Issue: Uses useState without 'use client'
    • Fix: Add 'use client' directive at top
  1. [错误] src/components/User.tsx:23
    • 规则:避免使用
      any
      类型
    • 代码:
      const data: any = response.json()
    • 修复建议:
      const data: UserResponse = response.json()
  2. [警告] src/components/Form.tsx:1
    • 规则:优先使用Server Components
    • 问题:使用useState但未添加'use client'
    • 修复建议:在顶部添加'use client'指令

Passed Checks

通过的检查项

  • Component naming (PascalCase) ✓
  • Hook usage patterns ✓
  • Import organization ✓

</usage_example>
</examples>
  • 组件命名(PascalCase) ✓
  • Hook使用模式 ✓
  • 导入组织 ✓

</usage_example>
</examples>

Rules

规则

  • Always check relevant expert skills for standards
  • Provide line numbers and specific fixes
  • Prioritize security and type safety issues
  • 始终参考相关专家技能中的标准
  • 提供行号与具体的修复建议
  • 优先处理安全与类型安全性问题

Memory Protocol (MANDATORY)

内存协议(强制性要求)

Before starting:
bash
cat .claude/context/memory/learnings.md
After completing:
  • New pattern ->
    .claude/context/memory/learnings.md
  • Issue found ->
    .claude/context/memory/issues.md
  • Decision made ->
    .claude/context/memory/decisions.md
ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.
开始前:
bash
cat .claude/context/memory/learnings.md
完成后:
  • 新模式 ->
    .claude/context/memory/learnings.md
  • 发现的问题 ->
    .claude/context/memory/issues.md
  • 做出的决策 ->
    .claude/context/memory/decisions.md
假设中断情况:你的上下文可能会重置。如果内容未存储在内存中,则视为未发生过。