AgentSkillsCN

phase-2-convention

第2阶段:编码约定与命名规则。 建立一致的编码标准、文件命名规则,以及项目结构。 接下来:$phase-3-mockup。 触发:约定、编码标准、命名规则、风格指南、Lint、 コーディングコンベンション、ネーミングルール、コードスタイル、コーディング規約、命名規則、 コーディング規範、命名規則、コードの慣習、convention de codage、Kodierkonvention 请勿用于:数据建模(请使用$phase-1-schema)、UI设计(请使用$phase-3-mockup)。

SKILL.md
--- frontmatter
name: phase-2-convention
description: |
  Phase 2: Coding Conventions and Naming Rules.
  Establish consistent coding standards, file naming, and project structure.
  Next: $phase-3-mockup.
  Triggers: convention, coding standard, naming rule, style guide, lint,
  코딩 컨벤션, 네이밍 규칙, 코드 스타일, コーディング規約, 命名規則,
  编码规范, 命名规则, convención de código, convention de codage, Kodierkonvention
  Do NOT use for: data modeling (use $phase-1-schema), UI design (use $phase-3-mockup).

Phase 2: Coding Conventions

Establish coding standards before writing application code.

Purpose

Phase 2 sets the rules everyone (human and AI) follows. Consistent conventions prevent confusion and reduce code review friction.

Actions

ActionDescriptionExample
startBegin Phase 2$phase-2-convention start
generateGenerate convention doc$phase-2-convention generate
lintCheck convention compliance$phase-2-convention lint

Deliverables

  1. Convention Document - docs/01-plan/convention.md
  2. ESLint/Prettier Config - Automated enforcement
  3. File Naming Rules - Directory and file naming patterns
  4. Component Naming Rules - UI component conventions
  5. Git Commit Conventions - Commit message format

Process

Step 1: Language & Framework Conventions

markdown
## TypeScript Conventions
- Strict mode enabled
- No `any` type (use `unknown` if needed)
- Interfaces over Types for object shapes
- Enum for fixed value sets
- Async/await over .then() chains

Step 2: Naming Rules

ElementConventionExample
Files (components)PascalCaseUserProfile.tsx
Files (utilities)camelCaseformatDate.ts
Files (styles)kebab-caseuser-profile.module.css
VariablescamelCaseuserName, isActive
ConstantsUPPER_SNAKEMAX_RETRY_COUNT
Types/InterfacesPascalCaseUserProfile, ApiResponse
HookscamelCase with useuseAuth, useQuery
ComponentsPascalCaseUserCard, NavBar
API routeskebab-case/api/user-profile
Databasesnake_caseuser_profile, created_at

Step 3: Directory Structure Rules

  • Group by feature, not by type
  • Max 3 levels deep
  • index.ts for barrel exports
  • tests/ next to source files

Step 4: Git Conventions

code
<type>(<scope>): <description>

Types: feat, fix, docs, style, refactor, test, chore
Scope: component or module name
Description: imperative mood, lowercase, no period

Examples:
- feat(auth): add social login support
- fix(api): handle null response from user endpoint

Step 5: Code Style Enforcement

json
{
  "extends": ["next/core-web-vitals", "prettier"],
  "rules": {
    "no-console": "warn",
    "no-unused-vars": "error",
    "@typescript-eslint/no-explicit-any": "error"
  }
}

Convention Patterns

See references/naming-conventions.md for detailed patterns.

Output Location

code
docs/01-plan/
├── convention.md      # Full convention document
project/
├── .eslintrc.json     # ESLint config
├── .prettierrc        # Prettier config
└── .editorconfig      # Editor config

Next Phase

When conventions are established, proceed to $phase-3-mockup for UI/UX design.

Common Mistakes

MistakeSolution
No automated enforcementSet up ESLint + Prettier from day 1
Too many rulesStart minimal, add rules as needed
Inconsistent namingUse a naming decision table
No commit conventionsUse commitlint with husky
Mixing conventionsOne language = one convention set