ogt-docs-rules

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

OGT 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
docs/rules/
and are organized by domain.
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 --> S5

When 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

SkillDomainUse When
ogt-docs-rules-code
Coding standardsTypeScript, naming, patterns, error handling
ogt-docs-rules-code-front
Frontend codeReact, components, state, styling
ogt-docs-rules-code-back
Backend codeAPI design, database, services
ogt-docs-rules-code-infra
InfrastructureDocker, CI/CD, deployment
ogt-docs-rules-git
Git workflowCommits, branches, PRs, reviews
Skill领域适用场景
ogt-docs-rules-code
编码标准TypeScript、命名规范、设计模式、错误处理
ogt-docs-rules-code-front
前端代码React、组件、状态管理、样式设计
ogt-docs-rules-code-back
后端代码API设计、数据库、服务架构
ogt-docs-rules-code-infra
基础设施Docker、CI/CD、部署流程
ogt-docs-rules-git
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 conventions

docs/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
rule.md
file.
每个规则都是一个文件夹,至少包含一个
rule.md
文件。

rule.md Template

rule.md 模板

markdown
undefined
markdown
undefined

Rule: {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_by
docs/rules/code/typescript/
├── rule.md
├── examples.md
├── .version
└── .enforced_by

rule.md

rule.md

markdown
undefined
markdown
undefined

Rule: 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

规则内容

  1. MUST enable
    "strict": true
    in tsconfig.json
  2. MUST NOT use
    @ts-ignore
    without explanatory comment
  3. MUST NOT use
    any
    type except in documented exceptions
  4. SHOULD prefer
    unknown
    over
    any
    for unknown types
  5. MUST fix all TypeScript errors before committing
  1. MUST 在tsconfig.json中启用
    "strict": true
  2. MUST NOT 在无解释注释的情况下使用
    @ts-ignore
  3. MUST NOT 使用
    any
    类型,除非有文档记录的例外情况
  4. SHOULD 优先使用
    unknown
    而非
    any
    来表示未知类型
  5. 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;
}
undefined
typescript
// 显式类型
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;
}
undefined

Incorrect

错误示例

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

例外情况

  1. Third-party library definitions that require
    any
  2. Migration of legacy JavaScript (with tracking issue)
  3. 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;
  1. 第三方库定义需要使用
    any
    类型
  2. 遗留JavaScript代码迁移(需关联跟踪议题)
  3. 测试模拟场景中,类型安全性优先级较低
使用例外情况时,需添加注释:
typescript
// 例外:遗留API返回无类型响应(见#123)
const data = legacyApi.fetch() as any;

Enforcement

执行方式

  • Automated:
    tsc --noEmit
    in pre-commit hook and CI
  • Automated: ESLint
    @typescript-eslint/no-explicit-any
  • Manual: Code review for exception documentation
  • 自动化:在提交前钩子和CI流程中执行
    tsc --noEmit
  • 自动化:ESLint规则
    @typescript-eslint/no-explicit-any
  • 人工:代码评审时检查例外情况的文档记录

References

参考资料

undefined
undefined

examples.md

examples.md

markdown
undefined
markdown
undefined

TypeScript 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 array
typescript
// 类型明显的局部变量
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 set
typescript
// 错误:无辨识符的松散联合类型
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];
}
undefined
typescript
// 正确:合理约束泛型
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 pipeline

tsc --noEmit
eslint --ext .ts,.tsx
pre-commit hook
CI pipeline

Example: 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_by
docs/rules/git/commits/
├── rule.md
├── examples.md
├── .version
└── .enforced_by

rule.md

rule.md

markdown
undefined
markdown
undefined

Rule: 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

类型

TypeUse When
feat
New feature
fix
Bug fix
docs
Documentation only
style
Formatting, no code change
refactor
Code change that neither fixes nor adds
perf
Performance improvement
test
Adding/updating tests
chore
Maintenance tasks
ci
CI/CD changes
类型适用场景
feat
新功能
fix
Bug修复
docs
仅文档变更
style
格式调整,无代码变更
refactor
代码重构,既非修复也非新增功能
perf
性能优化
test
添加/更新测试
chore
维护任务
ci
CI/CD流程变更

Requirements

要求

  1. MUST use lowercase type
  2. MUST use imperative mood in description ("add" not "added")
  3. MUST limit first line to 72 characters
  4. SHOULD include scope for clarity
  5. MUST reference issue number in footer for bug fixes
  6. MUST mark breaking changes with
    !
    or
    BREAKING CHANGE:
    footer
  1. MUST 使用小写类型
  2. MUST 在描述中使用祈使语气(如"add"而非"added")
  3. MUST 限制首行长度为72字符
  4. SHOULD 包含作用域以提升清晰度
  5. MUST 在页脚中关联Bug修复对应的议题编号
  6. 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
undefined
markdown
undefined

Commit 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 CI

commitlint
husky pre-commit
GitHub Actions CI

Creating 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

步骤

  1. Choose domain: code/, git/, docs/, style/
  2. Create folder:
    docs/rules/{domain}/{rule_name}/
  3. Write rule.md: Use template above
  4. Add examples.md: Comprehensive good/bad examples
  5. Create .version: Schema versioning
  6. Document .enforced_by: List enforcement mechanisms
  7. Configure automation: ESLint rules, commit hooks, CI checks
  8. Announce: Communicate new rule to team

  1. 选择领域:code/、git/、docs/、style/
  2. 创建文件夹
    docs/rules/{domain}/{rule_name}/
  3. 编写rule.md:使用上述模板
  4. 添加examples.md:包含全面的正确/错误示例
  5. 创建.version:版本管理
  6. 编写.enforced_by:列出执行机制
  7. 配置自动化:ESLint规则、提交钩子、CI检查
  8. 通知团队:向团队传达新规则

Signal Files Reference

标识文件参考

SignalTypeContentPurpose
.version
ContentJSON with schema, created, updatedTrack rule version
.enforced_by
ContentList of tools/processesDocument enforcement
.deprecated
Empty-Mark rule as deprecated
.superseded_by
ContentPath to new rulePoint to replacement
.approved_by_{name}
Empty-Track approval

标识文件类型内容用途
.version
内容文件包含schema、created、updated的JSON跟踪规则版本
.enforced_by
内容文件工具/流程列表记录执行方式
.deprecated
空文件-标记规则已废弃
.superseded_by
内容文件新规则的路径指向替代规则
.approved_by_{name}
空文件-跟踪审批状态

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个带解释的错误示例
  • 例外情况已记录
  • 执行机制已明确
  • 代码示例可编译/运行
  • 要求无歧义
  • 已关联相关规则