ogt-docs-rules
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOGT Docs - Rules
OGT 文档 - 规则
Root skill for managing project rules and standards. Rules define enforceable conventions that all contributors (human and AI) must follow.
这是管理项目规则与标准的核心Skill。规则定义了所有贡献者(人类和AI)必须遵守的可强制执行约定。
Overview
概述
Rules are the codified standards of a project. Unlike guidelines (suggestions) or documentation (information), rules are enforceable and verifiable. They live in and are organized by domain.
docs/rules/mermaid
flowchart TB
subgraph rules ["docs/rules/"]
direction TB
CODE["code/"]
GIT["git/"]
INFRA["infra/"]
DOCS["docs/"]
STYLE["style/"]
end
subgraph skills ["Specialized Skills"]
S1["ogt-docs-rules-code"]
S2["ogt-docs-rules-git"]
S3["ogt-docs-rules-code-front"]
S4["ogt-docs-rules-code-back"]
S5["ogt-docs-rules-code-infra"]
end
CODE --> S1
CODE --> S3
CODE --> S4
CODE --> S5
GIT --> S2
INFRA --> S5规则是项目的规范化标准。与指南(建议性)或文档(信息性)不同,规则是可强制执行且可验证的。它们存储在目录中,并按领域进行组织。
docs/rules/mermaid
flowchart TB
subgraph rules ["docs/rules/"]
direction TB
CODE["code/"]
GIT["git/"]
INFRA["infra/"]
DOCS["docs/"]
STYLE["style/"]
end
subgraph skills ["Specialized Skills"]
S1["ogt-docs-rules-code"]
S2["ogt-docs-rules-git"]
S3["ogt-docs-rules-code-front"]
S4["ogt-docs-rules-code-back"]
S5["ogt-docs-rules-code-infra"]
end
CODE --> S1
CODE --> S3
CODE --> S4
CODE --> S5
GIT --> S2
INFRA --> S5When to Use
适用场景
- Creating new project rules or standards
- Updating existing rules
- Looking up rules for a specific domain
- Enforcing rules during code review
- Setting up rules for a new project
- 创建新的项目规则或标准
- 更新现有规则
- 查询特定领域的规则
- 代码评审期间强制执行规则
- 为新项目配置规则
Sub-Skills
子Skill
| Skill | Domain | Use When |
|---|---|---|
| Coding standards | TypeScript, naming, patterns, error handling |
| Frontend code | React, components, state, styling |
| Backend code | API design, database, services |
| Infrastructure | Docker, CI/CD, deployment |
| Git workflow | Commits, branches, PRs, reviews |
| Skill | 领域 | 适用场景 |
|---|---|---|
| 编码标准 | TypeScript、命名规范、设计模式、错误处理 |
| 前端代码 | React、组件、状态管理、样式设计 |
| 后端代码 | API设计、数据库、服务架构 |
| 基础设施 | Docker、CI/CD、部署流程 |
| Git工作流 | 提交、分支、PR、代码评审 |
Folder Structure
目录结构
docs/rules/
├── code/ # Coding standards
│ ├── general/ # Cross-cutting code rules
│ │ ├── rule.md # Primary rule definition
│ │ ├── examples.md # Good/bad examples
│ │ ├── .version # Schema version
│ │ └── .enforced_by # How it's enforced (eslint, tsc, etc.)
│ │
│ ├── typescript/ # TypeScript-specific rules
│ │ ├── rule.md
│ │ ├── examples.md
│ │ └── .enforced_by
│ │
│ ├── naming/ # Naming conventions
│ │ ├── rule.md
│ │ ├── examples.md
│ │ └── .enforced_by
│ │
│ ├── front/ # Frontend-specific rules
│ │ ├── components/
│ │ ├── state/
│ │ ├── styling/
│ │ └── routing/
│ │
│ ├── back/ # Backend-specific rules
│ │ ├── api/
│ │ ├── database/
│ │ └── services/
│ │
│ └── infra/ # Infrastructure rules
│ ├── docker/
│ ├── ci/
│ └── deployment/
│
├── git/ # Git workflow rules
│ ├── commits/ # Commit message format
│ │ ├── rule.md
│ │ ├── examples.md
│ │ └── .enforced_by
│ │
│ ├── branches/ # Branch naming
│ │ ├── rule.md
│ │ └── examples.md
│ │
│ ├── pull_requests/ # PR requirements
│ │ ├── rule.md
│ │ └── template.md
│ │
│ └── reviews/ # Code review standards
│ ├── rule.md
│ └── checklist.md
│
├── docs/ # Documentation rules
│ ├── structure/ # Folder organization
│ ├── formatting/ # Markdown standards
│ └── comments/ # Code comments
│
└── style/ # Style guides
├── ui/ # UI/UX consistency
├── api/ # API style
└── naming/ # Naming conventionsdocs/rules/
├── code/ # 编码标准
│ ├── general/ # 跨领域代码规则
│ │ ├── rule.md # 核心规则定义
│ │ ├── examples.md # 正确/错误示例
│ │ ├── .version # 版本信息
│ │ └── .enforced_by # 执行方式(如eslint、tsc等)
│ │
│ ├── typescript/ # TypeScript专属规则
│ │ ├── rule.md
│ │ ├── examples.md
│ │ └── .enforced_by
│ │
│ ├── naming/ # 命名规范
│ │ ├── rule.md
│ │ ├── examples.md
│ │ └── .enforced_by
│ │
│ ├── front/ # 前端专属规则
│ │ ├── components/
│ │ ├── state/
│ │ ├── styling/
│ │ └── routing/
│ │
│ ├── back/ # 后端专属规则
│ │ ├── api/
│ │ ├── database/
│ │ └── services/
│ │
│ └── infra/ # 基础设施规则
│ ├── docker/
│ ├── ci/
│ └── deployment/
│
├── git/ # Git工作流规则
│ ├── commits/ # 提交消息格式
│ │ ├── rule.md
│ │ ├── examples.md
│ │ └── .enforced_by
│ │
│ ├── branches/ # 分支命名规范
│ │ ├── rule.md
│ │ └── examples.md
│ │
│ ├── pull_requests/ # PR要求
│ │ ├── rule.md
│ │ └── template.md
│ │
│ └── reviews/ # 代码评审标准
│ ├── rule.md
│ └── checklist.md
│
├── docs/ # 文档规则
│ ├── structure/ # 目录组织规范
│ ├── formatting/ # Markdown标准
│ └── comments/ # 代码注释规范
│
└── style/ # 风格指南
├── ui/ # UI/UX一致性
├── api/ # API风格
└── naming/ # 命名规范Rule Definition Structure
规则定义结构
Every rule is a folder containing at minimum a file.
rule.md每个规则都是一个文件夹,至少包含一个文件。
rule.mdrule.md Template
rule.md 模板
markdown
undefinedmarkdown
undefinedRule: {Rule Name}
规则:{规则名称}
Summary
概述
One sentence stating the rule clearly and unambiguously.
用一句话清晰、明确地描述规则。
Rationale
理由
Why this rule exists. What problems it prevents. What benefits it provides.
说明该规则存在的原因,能预防哪些问题,带来哪些收益。
The Rule
规则内容
Clear, specific statement of what MUST, SHOULD, or MUST NOT be done.
Use RFC 2119 keywords:
- MUST / REQUIRED - Absolute requirement
- MUST NOT / SHALL NOT - Absolute prohibition
- SHOULD / RECOMMENDED - Recommended but exceptions exist
- SHOULD NOT - Not recommended but exceptions exist
- MAY / OPTIONAL - Truly optional
清晰、具体地说明必须、应该或禁止执行的操作。
使用RFC 2119关键词:
- MUST / REQUIRED - 强制性要求
- MUST NOT / SHALL NOT - 严格禁止
- SHOULD / RECOMMENDED - 推荐执行,但允许例外
- SHOULD NOT - 不推荐执行,但允许例外
- MAY / OPTIONAL - 完全可选
Examples
示例
Correct
正确示例
{Show correct usage}
{展示正确用法}
Incorrect
错误示例
{Show incorrect usage with explanation}
{展示错误用法并说明原因}
Exceptions
例外情况
Documented cases where this rule may be relaxed.
记录可放宽该规则的场景。
Enforcement
执行方式
How this rule is enforced:
- Automated (linter, type checker, CI)
- Manual (code review)
- Both
说明该规则的执行机制:
- 自动化(如代码检查工具、类型检查器、CI流程)
- 人工(如代码评审)
- 两者结合
References
参考资料
- Related rules
- External standards
- Tooling documentation
---- 相关规则
- 外部标准
- 工具文档
---Example: docs/rules/code/typescript/
示例:docs/rules/code/typescript/
Complete example of a TypeScript rules folder.
TypeScript规则文件夹的完整示例。
Folder Structure
目录结构
docs/rules/code/typescript/
├── rule.md
├── examples.md
├── .version
└── .enforced_bydocs/rules/code/typescript/
├── rule.md
├── examples.md
├── .version
└── .enforced_byrule.md
rule.md
markdown
undefinedmarkdown
undefinedRule: TypeScript Strict Mode
规则:TypeScript 严格模式
Summary
概述
All TypeScript code MUST compile with strict mode enabled.
所有TypeScript代码必须在严格模式下编译通过。
Rationale
理由
Strict mode catches common errors at compile time:
- Implicit any types
- Null/undefined access
- Unused variables
- Missing return types
This prevents runtime errors and improves code quality.
严格模式可在编译阶段捕获常见错误:
- 隐式any类型
- Null/undefined访问
- 未使用变量
- 缺失返回类型
这能避免运行时错误,提升代码质量。
The Rule
规则内容
- MUST enable in tsconfig.json
"strict": true - MUST NOT use without explanatory comment
@ts-ignore - MUST NOT use type except in documented exceptions
any - SHOULD prefer over
unknownfor unknown typesany - MUST fix all TypeScript errors before committing
- MUST 在tsconfig.json中启用
"strict": true - MUST NOT 在无解释注释的情况下使用
@ts-ignore - MUST NOT 使用类型,除非有文档记录的例外情况
any - SHOULD 优先使用而非
unknown来表示未知类型any - MUST 在提交代码前修复所有TypeScript错误
Examples
示例
Correct
正确示例
typescript
// Explicit types
function calculateTotal(items: CartItem[]): number {
return items.reduce((sum, item) => sum + item.price, 0);
}
// Unknown instead of any
function parseJSON(text: string): unknown {
return JSON.parse(text);
}
// Type guards for unknown
function isUser(value: unknown): value is User {
return typeof value === "object" && value !== null && "id" in value;
}undefinedtypescript
// 显式类型
function calculateTotal(items: CartItem[]): number {
return items.reduce((sum, item) => sum + item.price, 0);
}
// 使用unknown而非any
function parseJSON(text: string): unknown {
return JSON.parse(text);
}
// 为unknown类型添加类型守卫
function isUser(value: unknown): value is User {
return typeof value === "object" && value !== null && "id" in value;
}undefinedIncorrect
错误示例
typescript
// Implicit any - TS7006
function process(data) {
// ERROR: Parameter 'data' implicitly has 'any' type
return data.value;
}
// Using any
function handleResponse(response: any) {
// AVOID: Use unknown or specific type
return response.data;
}
// ts-ignore without comment
// @ts-ignore // BAD: No explanation
const result = brokenLibrary.call();typescript
// 隐式any - TS7006错误
function process(data) {
// 错误:参数'data'隐式拥有'any'类型
return data.value;
}
// 使用any类型
function handleResponse(response: any) {
// 避免:使用unknown或具体类型
return response.data;
}
// 无注释的ts-ignore
// @ts-ignore // 错误:未说明原因
const result = brokenLibrary.call();Exceptions
例外情况
- Third-party library definitions that require
any - Migration of legacy JavaScript (with tracking issue)
- Test mocks where type safety is less critical
When using exceptions, add comment:
typescript
// Exception: Legacy API returns untyped response (see #123)
const data = legacyApi.fetch() as any;- 第三方库定义需要使用类型
any - 遗留JavaScript代码迁移(需关联跟踪议题)
- 测试模拟场景中,类型安全性优先级较低
使用例外情况时,需添加注释:
typescript
// 例外:遗留API返回无类型响应(见#123)
const data = legacyApi.fetch() as any;Enforcement
执行方式
- Automated: in pre-commit hook and CI
tsc --noEmit - Automated: ESLint
@typescript-eslint/no-explicit-any - Manual: Code review for exception documentation
- 自动化:在提交前钩子和CI流程中执行
tsc --noEmit - 自动化:ESLint规则
@typescript-eslint/no-explicit-any - 人工:代码评审时检查例外情况的文档记录
References
参考资料
- TypeScript Strict Mode
- docs/rules/code/general/ - General coding standards
undefined- TypeScript Strict Mode
- docs/rules/code/general/ - 通用编码标准
undefinedexamples.md
examples.md
markdown
undefinedmarkdown
undefinedTypeScript Examples
TypeScript 示例
Extended examples for TypeScript rules.
TypeScript规则的扩展示例。
Type Inference vs Explicit Types
类型推断 vs 显式类型
When to Use Explicit Types
何时使用显式类型
typescript
// Function return types - ALWAYS explicit
function fetchUser(id: string): Promise<User> {
return api.get(`/users/${id}`);
}
// Exported constants - ALWAYS explicit
export const DEFAULT_TIMEOUT: number = 5000;
// Complex objects - ALWAYS explicit
const config: AppConfig = {
apiUrl: process.env.API_URL,
timeout: 5000,
};typescript
// 函数返回类型 - 始终显式声明
function fetchUser(id: string): Promise<User> {
return api.get(`/users/${id}`);
}
// 导出常量 - 始终显式声明
export const DEFAULT_TIMEOUT: number = 5000;
// 复杂对象 - 始终显式声明
const config: AppConfig = {
apiUrl: process.env.API_URL,
timeout: 5000,
};When Inference is Acceptable
何时可使用类型推断
typescript
// Local variables with obvious types
const count = 0; // Inferred as number
const name = "test"; // Inferred as string
const items = [1, 2, 3]; // Inferred as number[]
// Arrow functions in callbacks
users.filter((user) => user.active); // Parameter type inferred from arraytypescript
// 类型明显的局部变量
const count = 0; // 推断为number类型
const name = "test"; // 推断为string类型
const items = [1, 2, 3]; // 推断为number[]类型
// 回调中的箭头函数
users.filter((user) => user.active); // 参数类型从数组推断Union Types
联合类型
Discriminated Unions
可辨识联合类型
typescript
// CORRECT: Use discriminated unions
type Result<T> = { success: true; data: T } | { success: false; error: Error };
function handleResult<T>(result: Result<T>) {
if (result.success) {
console.log(result.data); // TypeScript knows data exists
} else {
console.error(result.error); // TypeScript knows error exists
}
}typescript
// 正确:使用可辨识联合类型
type Result<T> = { success: true; data: T } | { success: false; error: Error };
function handleResult<T>(result: Result<T>) {
if (result.success) {
console.log(result.data); // TypeScript知道data存在
} else {
console.error(result.error); // TypeScript知道error存在
}
}Avoid Loose Unions
避免松散联合类型
typescript
// INCORRECT: Loose union without discriminant
type Response = {
data?: User;
error?: Error;
};
// Problem: Both could be undefined, or both could be settypescript
// 错误:无辨识符的松散联合类型
type Response = {
data?: User;
error?: Error;
};
// 问题:两者都可能未定义,或同时存在Generic Constraints
泛型约束
typescript
// CORRECT: Constrain generics appropriately
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
// INCORRECT: Unconstrained generic
function getValue<T>(obj: T, key: string): any {
// Returns any!
return (obj as any)[key];
}undefinedtypescript
// 正确:合理约束泛型
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
// 错误:无约束泛型
function getValue<T>(obj: T, key: string): any {
// 返回any类型!
return (obj as any)[key];
}undefined.version
.version
json
{ "schema": "1.0", "created": "2026-01-15T10:00:00Z", "updated": "2026-02-01T14:00:00Z" }json
{ "schema": "1.0", "created": "2026-01-15T10:00:00Z", "updated": "2026-02-01T14:00:00Z" }.enforced_by
.enforced_by
tsc --noEmit
eslint --ext .ts,.tsx
pre-commit hook
CI pipelinetsc --noEmit
eslint --ext .ts,.tsx
pre-commit hook
CI pipelineExample: docs/rules/git/commits/
示例:docs/rules/git/commits/
Complete example of commit message rules.
提交消息规则的完整示例。
Folder Structure
目录结构
docs/rules/git/commits/
├── rule.md
├── examples.md
├── .version
└── .enforced_bydocs/rules/git/commits/
├── rule.md
├── examples.md
├── .version
└── .enforced_byrule.md
rule.md
markdown
undefinedmarkdown
undefinedRule: Commit Message Format
规则:提交消息格式
Summary
概述
All commit messages MUST follow Conventional Commits format.
所有提交消息必须遵循Conventional Commits格式。
Rationale
理由
Consistent commit messages enable:
- Automated changelog generation
- Semantic versioning automation
- Easy history navigation
- Clear communication of changes
一致的提交消息可实现:
- 自动生成变更日志
- 语义化版本自动管理
- 便捷的历史记录导航
- 清晰的变更沟通
The Rule
规则内容
Format
格式
<type>(<scope>): <description>
[optional body]
[optional footer(s)]
<type>(<scope>): <description>
[可选正文]
[可选页脚]
Types
类型
| Type | Use When |
|---|---|
| New feature |
| Bug fix |
| Documentation only |
| Formatting, no code change |
| Code change that neither fixes nor adds |
| Performance improvement |
| Adding/updating tests |
| Maintenance tasks |
| CI/CD changes |
| 类型 | 适用场景 |
|---|---|
| 新功能 |
| Bug修复 |
| 仅文档变更 |
| 格式调整,无代码变更 |
| 代码重构,既非修复也非新增功能 |
| 性能优化 |
| 添加/更新测试 |
| 维护任务 |
| CI/CD流程变更 |
Requirements
要求
- MUST use lowercase type
- MUST use imperative mood in description ("add" not "added")
- MUST limit first line to 72 characters
- SHOULD include scope for clarity
- MUST reference issue number in footer for bug fixes
- MUST mark breaking changes with or
!footerBREAKING CHANGE:
- MUST 使用小写类型
- MUST 在描述中使用祈使语气(如"add"而非"added")
- MUST 限制首行长度为72字符
- SHOULD 包含作用域以提升清晰度
- MUST 在页脚中关联Bug修复对应的议题编号
- MUST 使用或
!页脚标记破坏性变更BREAKING CHANGE:
Examples
示例
Correct
正确示例
feat(auth): add Steam OAuth provider
Implement Steam OpenID authentication flow.
Follows existing Google/Discord pattern.
Closes #456
fix(api): handle null response from legacy endpoint
The /v0/users endpoint can return null for deleted users.
Add null check and return 404 instead of 500.
Fixes #789
refactor(components): extract CardBase from entity cards
DRY refactor - all entity cards now extend CardBase.
No functional changes.
feat(api)!: change authentication header format
BREAKING CHANGE: Authorization header now requires "Bearer " prefix.
Migration guide: docs/guides/auth_migration.md
feat(auth): add Steam OAuth provider
Implement Steam OpenID authentication flow.
Follows existing Google/Discord pattern.
Closes #456
fix(api): handle null response from legacy endpoint
The /v0/users endpoint can return null for deleted users.
Add null check and return 404 instead of 500.
Fixes #789
refactor(components): extract CardBase from entity cards
DRY refactor - all entity cards now extend CardBase.
No functional changes.
feat(api)!: change authentication header format
BREAKING CHANGE: Authorization header now requires "Bearer " prefix.
Migration guide: docs/guides/auth_migration.md
Incorrect
错误示例
Fixed bug // No type, no scope, vague
FEAT: Add new feature // Wrong case
feat(auth): Added Steam OAuth // Past tense
feat: implement the new user authentication system with Steam support and update all related components // Too long
Fixed bug // 无类型、无作用域、描述模糊
FEAT: Add new feature // 大小写错误
feat(auth): Added Steam OAuth // 过去式
feat: implement the new user authentication system with Steam support and update all related components // 过长
Exceptions
例外情况
- Merge commits may use default message
- Revert commits may use git's default format
- 合并提交可使用默认消息
- 回滚提交可使用Git默认格式
Enforcement
执行方式
- Automated: commitlint in pre-commit hook
- Automated: CI check on PR
- Manual: PR review
- 自动化:提交前钩子中的commitlint
- 自动化:PR中的CI检查
- 人工:PR评审
References
参考资料
examples.md
examples.md
markdown
undefinedmarkdown
undefinedCommit Message Examples
提交消息示例
Feature Commits
功能提交
feat(creatures): add CR filtering to creature list
Allow filtering creatures by Challenge Rating range.
Uses dual-handle slider component.
Related: #234
feat(search): implement fuzzy search with MiniSearch
Replace substring matching with indexed fuzzy search.
Results ranked by relevance score.
Performance: <16ms for 10k entries
Closes #567
feat(creatures): add CR filtering to creature list
Allow filtering creatures by Challenge Rating range.
Uses dual-handle slider component.
Related: #234
feat(search): implement fuzzy search with MiniSearch
Replace substring matching with indexed fuzzy search.
Results ranked by relevance score.
Performance: <16ms for 10k entries
Closes #567
Bug Fix Commits
Bug修复提交
fix(cards): prevent image flash on card hover
Card images were reloading on every hover due to
missing key prop in map. Add stable key based on
entity slug.
Fixes #890
fix(auth): handle expired refresh tokens gracefully
When refresh token expires, redirect to login instead
of showing error page. Clear local storage on redirect.
Fixes #891
Fixes #892
fix(cards): prevent image flash on card hover
Card images were reloading on every hover due to
missing key prop in map. Add stable key based on
entity slug.
Fixes #890
fix(auth): handle expired refresh tokens gracefully
When refresh token expires, redirect to login instead
of showing error page. Clear local storage on redirect.
Fixes #891
Fixes #892
Refactor Commits
重构提交
refactor(services): extract API client from services
Move HTTP logic to dedicated ApiClient class.
Services now use dependency injection.
No functional changes. Improves testability.
refactor(services): extract API client from services
Move HTTP logic to dedicated ApiClient class.
Services now use dependency injection.
No functional changes. Improves testability.
Documentation Commits
文档提交
docs(readme): add Docker setup instructions
Document docker-compose workflow for new developers.
Include troubleshooting section for common issues.
docs(readme): add Docker setup instructions
Document docker-compose workflow for new developers.
Include troubleshooting section for common issues.
Breaking Change Commits
破坏性变更提交
feat(api)!: rename /monsters to /creatures
BREAKING CHANGE: All /api/monsters/_ endpoints now at /api/creatures/_
Migration:
- Update all fetch calls
- /monsters/:slug -> /creatures/:slug
- Search params unchanged
Deprecation notice sent 2026-01-01.
Old endpoints removed 2026-02-01.
undefined
feat(api)!: rename /monsters to /creatures
BREAKING CHANGE: All /api/monsters/_ endpoints now at /api/creatures/_
Migration:
- Update all fetch calls
- /monsters/:slug -> /creatures/:slug
- Search params unchanged
Deprecation notice sent 2026-01-01.
Old endpoints removed 2026-02-01.
undefined.enforced_by
.enforced_by
commitlint
husky pre-commit
GitHub Actions CIcommitlint
husky pre-commit
GitHub Actions CICreating New Rules
创建新规则
mermaid
flowchart TD
A[Identify Need for Rule] --> B{Rule Type?}
B -->|Code| C[docs/rules/code/]
B -->|Git| D[docs/rules/git/]
B -->|Docs| E[docs/rules/docs/]
B -->|Style| F[docs/rules/style/]
C --> G[Create Rule Folder]
D --> G
E --> G
F --> G
G --> H[Write rule.md]
H --> I[Add examples.md]
I --> J[Set .version]
J --> K[Document .enforced_by]
K --> L{Automated Enforcement?}
L -->|Yes| M[Configure Tooling]
L -->|No| N[Add to Review Checklist]
M --> O[Add to CI]
N --> O
O --> P[Announce to Team]mermaid
flowchart TD
A[Identify Need for Rule] --> B{Rule Type?}
B -->|Code| C[docs/rules/code/]
B -->|Git| D[docs/rules/git/]
B -->|Docs| E[docs/rules/docs/]
B -->|Style| F[docs/rules/style/]
C --> G[Create Rule Folder]
D --> G
E --> G
F --> G
G --> H[Write rule.md]
H --> I[Add examples.md]
I --> J[Set .version]
J --> K[Document .enforced_by]
K --> L{Automated Enforcement?}
L -->|Yes| M[Configure Tooling]
L -->|No| N[Add to Review Checklist]
M --> O[Add to CI]
N --> O
O --> P[Announce to Team]Steps
步骤
- Choose domain: code/, git/, docs/, style/
- Create folder:
docs/rules/{domain}/{rule_name}/ - Write rule.md: Use template above
- Add examples.md: Comprehensive good/bad examples
- Create .version: Schema versioning
- Document .enforced_by: List enforcement mechanisms
- Configure automation: ESLint rules, commit hooks, CI checks
- Announce: Communicate new rule to team
- 选择领域:code/、git/、docs/、style/
- 创建文件夹:
docs/rules/{domain}/{rule_name}/ - 编写rule.md:使用上述模板
- 添加examples.md:包含全面的正确/错误示例
- 创建.version:版本管理
- 编写.enforced_by:列出执行机制
- 配置自动化:ESLint规则、提交钩子、CI检查
- 通知团队:向团队传达新规则
Signal Files Reference
标识文件参考
| Signal | Type | Content | Purpose |
|---|---|---|---|
| Content | JSON with schema, created, updated | Track rule version |
| Content | List of tools/processes | Document enforcement |
| Empty | - | Mark rule as deprecated |
| Content | Path to new rule | Point to replacement |
| Empty | - | Track approval |
| 标识文件 | 类型 | 内容 | 用途 |
|---|---|---|---|
| 内容文件 | 包含schema、created、updated的JSON | 跟踪规则版本 |
| 内容文件 | 工具/流程列表 | 记录执行方式 |
| 空文件 | - | 标记规则已废弃 |
| 内容文件 | 新规则的路径 | 指向替代规则 |
| 空文件 | - | 跟踪审批状态 |
Rule Quality Checklist
规则质量检查清单
Before finalizing a rule:
- Summary is one clear sentence
- Rationale explains WHY (not just what)
- Uses RFC 2119 keywords correctly
- Has at least 2 correct examples
- Has at least 2 incorrect examples with explanations
- Exceptions are documented
- Enforcement mechanism is specified
- Examples compile/work if code
- No ambiguity in requirements
- Cross-referenced with related rules
在确定规则最终版本前:
- 概述为清晰的单句
- 理由说明了原因(而非仅内容)
- 正确使用RFC 2119关键词
- 至少包含2个正确示例
- 至少包含2个带解释的错误示例
- 例外情况已记录
- 执行机制已明确
- 代码示例可编译/运行
- 要求无歧义
- 已关联相关规则