重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
coding-rules by kimny1143/claude-code-template
npx skills add https://github.com/kimny1143/claude-code-template --skill coding-rules项目通用的编码规则。
// ✅ 显式类型定义
interface User {
id: string;
email: string;
name: string;
createdAt: Date;
}
// ✅ 类型推断明确时可以省略
const users = await repository.findAll(); // 返回值类型从函数推断
// ❌ 不要使用 any
const data: any = response.json();
// ✅ 使用 unknown 进行安全处理
const data: unknown = await response.json();
if (isUser(data)) {
console.log(data.email);
}
// ✅ Optional chaining
const email = user?.profile?.email;
// ✅ Nullish coalescing
const name = user.name ?? 'Anonymous';
// ❌ 不推荐
const name = user.name || 'Anonymous'; // 空字符串也是 falsy
// 1. 外部库
import { useState } from 'react';
import { z } from 'zod';
// 2. 内部模块(别名)
import { db } from '@/db';
import { User } from '@/types';
// 3. 相对导入
import { helper } from './utils';
import styles from './styles.module.css';
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 种类 | 规则 | 示例 |
|---|---|---|
| 变量・函数 | camelCase | getUserById, isActive |
| 常量 | UPPER_SNAKE_CASE | MAX_RETRY_COUNT |
| 类・类型 | PascalCase | UserService, CreateUserInput |
| 文件 | kebab-case | user-service.ts |
| React组件 | PascalCase | UserCard.tsx |
| 环境变量 | UPPER_SNAKE_CASE | DATABASE_URL |
// ✅ 使用 is/has/can/should 前缀
const isActive = true;
const hasPermission = user.role === 'admin';
const canEdit = isOwner || isAdmin;
const shouldRefetch = isStale && !isLoading;
// ❌ 多个职责
async function processUser(userId: string) {
const user = await db.select().from(users).where(eq(users.id, userId));
await sendEmail(user.email);
await updateLastLogin(userId);
return user;
}
// ✅ 拆分
async function getUser(userId: string) {
return db.select().from(users).where(eq(users.id, userId));
}
async function notifyUser(email: string) {
await sendEmail(email);
}
async function recordLogin(userId: string) {
await updateLastLogin(userId);
}
// ❌ 嵌套过深
function processData(data: Data | null) {
if (data) {
if (data.isValid) {
if (data.items.length > 0) {
return data.items.map(process);
}
}
}
return [];
}
// ✅ 提前返回
function processData(data: Data | null) {
if (!data) return [];
if (!data.isValid) return [];
if (data.items.length === 0) return [];
return data.items.map(process);
}
// ✅ 自定义错误类
class ValidationError extends Error {
constructor(
message: string,
public field: string
) {
super(message);
this.name = 'ValidationError';
}
}
// ✅ 适当的错误处理
try {
await riskyOperation();
} catch (error) {
if (error instanceof ValidationError) {
return apiError(error.message, { status: 400 });
}
console.error('Unexpected error:', error);
return apiError('Internal error', { status: 500 });
}
// ✅ 解释 WHY
// 由于 Stripe API 的限制,需要每 100 条进行批处理
const BATCH_SIZE = 100;
// ❌ 解释 WHAT(读代码就能明白)
// 获取用户
const user = await getUser(id);
// ✅ TODO/FIXME 附带 issue 编号
// TODO(#123): 实现缓存后删除
// FIXME(#456): 需要处理竞态条件
// Server Component (默认)
// - 数据获取
// - 访问机密信息
// - 减少包大小
// Client Component ('use client')
// - useState, useEffect
// - 事件处理器
// - 浏览器API
// ✅ 最小化的客户端组件
'use client';
export function LikeButton({ postId }: { postId: string }) {
const [liked, setLiked] = useState(false);
return <button onClick={() => setLiked(!liked)}>Like</button>;
}
// ✅ 类型定义
interface UserCardProps {
user: User;
onEdit?: (id: string) => void;
className?: string;
}
export function UserCard({ user, onEdit, className }: UserCardProps) {
// ...
}
feat: 新增功能
fix: 修复错误
docs: 文档
refactor: 重构
test: 测试
chore: 其他
feat: add user authentication
fix: resolve login redirect loop
docs: update API documentation
refactor: extract validation logic to separate module
test: add unit tests for UserService
chore: update dependencies
Weekly Installs
56
Repository
First Seen
Feb 9, 2026
Security Audits
Installed on
claude-code51
codex23
gemini-cli23
opencode22
github-copilot21
cursor21
プロジェクト共通のコーディングルール。
// ✅ 明示的な型定義
interface User {
id: string;
email: string;
name: string;
createdAt: Date;
}
// ✅ 型推論が明確な場合は省略OK
const users = await repository.findAll(); // 戻り値の型は関数から推論
// ❌ any は使わない
const data: any = response.json();
// ✅ unknown を使って安全に処理
const data: unknown = await response.json();
if (isUser(data)) {
console.log(data.email);
}
// ✅ Optional chaining
const email = user?.profile?.email;
// ✅ Nullish coalescing
const name = user.name ?? 'Anonymous';
// ❌ 非推奨
const name = user.name || 'Anonymous'; // 空文字もfalsy
// 1. 外部ライブラリ
import { useState } from 'react';
import { z } from 'zod';
// 2. 内部モジュール(エイリアス)
import { db } from '@/db';
import { User } from '@/types';
// 3. 相対インポート
import { helper } from './utils';
import styles from './styles.module.css';
| 種類 | 規則 | 例 |
|---|---|---|
| 変数・関数 | camelCase | getUserById, isActive |
| 定数 | UPPER_SNAKE_CASE | MAX_RETRY_COUNT |
| クラス・型 | PascalCase | UserService, CreateUserInput |
| ファイル | kebab-case | user-service.ts |
| Reactコンポーネント |
// ✅ is/has/can/should プレフィックス
const isActive = true;
const hasPermission = user.role === 'admin';
const canEdit = isOwner || isAdmin;
const shouldRefetch = isStale && !isLoading;
// ❌ 複数の責任
async function processUser(userId: string) {
const user = await db.select().from(users).where(eq(users.id, userId));
await sendEmail(user.email);
await updateLastLogin(userId);
return user;
}
// ✅ 分割
async function getUser(userId: string) {
return db.select().from(users).where(eq(users.id, userId));
}
async function notifyUser(email: string) {
await sendEmail(email);
}
async function recordLogin(userId: string) {
await updateLastLogin(userId);
}
// ❌ ネスト深い
function processData(data: Data | null) {
if (data) {
if (data.isValid) {
if (data.items.length > 0) {
return data.items.map(process);
}
}
}
return [];
}
// ✅ 早期リターン
function processData(data: Data | null) {
if (!data) return [];
if (!data.isValid) return [];
if (data.items.length === 0) return [];
return data.items.map(process);
}
// ✅ カスタムエラークラス
class ValidationError extends Error {
constructor(
message: string,
public field: string
) {
super(message);
this.name = 'ValidationError';
}
}
// ✅ 適切なエラー処理
try {
await riskyOperation();
} catch (error) {
if (error instanceof ValidationError) {
return apiError(error.message, { status: 400 });
}
console.error('Unexpected error:', error);
return apiError('Internal error', { status: 500 });
}
// ✅ WHYを説明
// Stripe APIの制限により、100件ずつバッチ処理する必要がある
const BATCH_SIZE = 100;
// ❌ WHATを説明(コードを読めばわかる)
// ユーザーを取得する
const user = await getUser(id);
// ✅ TODO/FIXME は issue番号付き
// TODO(#123): キャッシュ実装後に削除
// FIXME(#456): 競合状態の対応が必要
// Server Component (デフォルト)
// - データフェッチ
// - 機密情報アクセス
// - バンドルサイズ削減
// Client Component ('use client')
// - useState, useEffect
// - イベントハンドラ
// - ブラウザAPI
// ✅ 最小限のクライアントコンポーネント
'use client';
export function LikeButton({ postId }: { postId: string }) {
const [liked, setLiked] = useState(false);
return <button onClick={() => setLiked(!liked)}>Like</button>;
}
// ✅ 型定義
interface UserCardProps {
user: User;
onEdit?: (id: string) => void;
className?: string;
}
export function UserCard({ user, onEdit, className }: UserCardProps) {
// ...
}
feat: 新機能追加
fix: バグ修正
docs: ドキュメント
refactor: リファクタリング
test: テスト
chore: その他
feat: add user authentication
fix: resolve login redirect loop
docs: update API documentation
refactor: extract validation logic to separate module
test: add unit tests for UserService
chore: update dependencies
Weekly Installs
56
Repository
First Seen
Feb 9, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code51
codex23
gemini-cli23
opencode22
github-copilot21
cursor21
代码安全审查清单:最佳实践与漏洞防范指南(含密钥管理、SQL注入防护)
1,700 周安装
通用写作AI助手:专业内容创作流程与素材整合工具,提升写作效率与质量
65 周安装
Segment自动化集成:通过Rube MCP和Composio实现客户数据平台自动化操作
65 周安装
CircleCI自动化指南:通过Rube MCP与Composio实现CI/CD流水线自动触发与监控
65 周安装
JUnit 5 单元测试教程:Java/Kotlin 测试编写、Mockito 模拟与最佳实践
66 周安装
Excalidraw 图表生成器 - Python 编程生成可编辑图表,导出SVG/PNG
66 周安装
Dojo 客户端集成指南:JavaScript/TypeScript SDK、Unity、Unreal 游戏引擎连接教程
66 周安装
| PascalCase |
UserCard.tsx |
| 環境変数 | UPPER_SNAKE_CASE | DATABASE_URL |