coding-rules
1
总安装量
1
周安装量
#42509
全站排名
安装命令
npx skills add https://github.com/kimny1143/claude-code-template --skill coding-rules
Agent 安装分布
mcpjam
1
claude-code
1
replit
1
junie
1
windsurf
1
zencoder
1
Skill 文档
coding-rules – ã³ã¼ãã£ã³ã°è¦ç´
ããã¸ã§ã¯ãå ±éã®ã³ã¼ãã£ã³ã°ã«ã¼ã«ã
1. TypeScript
åå®ç¾©
// â
æç¤ºçãªåå®ç¾©
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);
}
Null/Undefined
// â
Optional chaining
const email = user?.profile?.email;
// â
Nullish coalescing
const name = user.name ?? 'Anonymous';
// â 鿍奍
const name = user.name || 'Anonymous'; // 空æåãfalsy
2. ã¤ã³ãã¼ãé åº
// 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';
3. å½åè¦å
| ç¨®é¡ | è¦å | ä¾ |
|---|---|---|
| 夿°ã»é¢æ° | 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 |
Booleanå½å
// â
is/has/can/should ãã¬ãã£ãã¯ã¹
const isActive = true;
const hasPermission = user.role === 'admin';
const canEdit = isOwner || isAdmin;
const shouldRefetch = isStale && !isLoading;
4. 颿°
åä¸è²¬ä»»
// â è¤æ°ã®è²¬ä»»
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);
}
5. ã¨ã©ã¼ãã³ããªã³ã°
// â
ã«ã¹ã¿ã ã¨ã©ã¼ã¯ã©ã¹
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 });
}
6. ã³ã¡ã³ã
// â
WHYã説æ
// Stripe APIã®å¶éã«ããã100ä»¶ãã¤ãããå¦çããå¿
è¦ããã
const BATCH_SIZE = 100;
// â WHATã説æï¼ã³ã¼ããèªãã°ãããï¼
// ã¦ã¼ã¶ã¼ãåå¾ãã
const user = await getUser(id);
// â
TODO/FIXME 㯠issueçªå·ä»ã
// TODO(#123): ãã£ãã·ã¥å®è£
å¾ã«åé¤
// FIXME(#456): ç«¶åç¶æ
ã®å¯¾å¿ãå¿
è¦
7. React/Next.js
Server vs Client Components
// 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>;
}
Props
// â
åå®ç¾©
interface UserCardProps {
user: User;
onEdit?: (id: string) => void;
className?: string;
}
export function UserCard({ user, onEdit, className }: UserCardProps) {
// ...
}
8. Git ã³ããã
Conventional Commits
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