coding-standards
БесплатноБез исполняемых скриптовНе проверенReact 19 and TypeScript coding standards for Portfolio Buddy 2. Use when: writing new components, reviewing code, refactoring, or ensuring consistency…
от aiskillstore★ 509 звёзд на GitHubОб этом скилле
Coding Standards - Portfolio Buddy 2
React 19 Patterns
Component Structure
// Good: Functional component with TypeScript
interface MetricsTableProps {
data: Metric[]
onSelect: (id: string) => void
}
export function MetricsTable({ data, onSelect }: MetricsTableProps) {
// Hooks at top
const [selected, setSelected] = useState<Set<string>>(new Set())
// Derived state with useMemo
const sortedData = useMemo(() =>
data.sort((a, b) => b.sharpe - a.sharpe),
[data]
)
// Event handlers with useCallback
const handleSelect = useCallback((id: string) => {
setSelected(prev => new Set(prev).add(id))
onSelect(id)
}, [onSelect])
// Render
return <div>...</div>
}
Hooks Rules
- Only at top level - No hooks in conditionals or loops
- Custom hooks start with
use- useMetrics, usePortfolio, useSorting - Dependencies array complete - All deps in useEffect/useMemo/useCallback
- Cleanup on unmount - Return cleanup function from useEffect
State Management
Portfolio Buddy 2 uses PLAIN REACT HOOKS ONLY:
- Local UI state →
useState - Derived state →
useMemo - Stable callbacks →
useCallback - DOM/value refs →
useRef
NO global state libraries:
- ❌ No TanStack Query
- ❌ No Zustand
- ❌ No Redux
- ❌ No Jotai
Pattern: Props down, custom hooks for shared logic
// State management example
const [files, setFiles] = useState<File[]>([])
const [dateRange, setDateRange] = useState({ start: null, end: null })
// Derived state
const filteredData = useMemo(() =>
filterByDateRange(files, dateRange),
[files, dateRange]
)
// Stable callback
const handleUpload = useCallback((newFile: File) => {
setFiles(prev => [...prev, newFile])
}, [])
TypeScript Standards
No any Types
// Bad
const data: any = fetchData()
// Good
interface TradeData {
symbol: string
date: Date
pnl: number
}
const data: TradeData[] = fetchData()
Current Violations (Tech Debt):
- usePortfolio.ts: 11 instances (trade/metrics types)
- useMetrics.ts: 4 instances (sort comparisons)
- dataUtils.ts: 1 instance (Metrics interface)
- Total: 15 violations to fix (originally 16)
Strict Null Checks
// Bad
const value = data.find(x => x.id === id)
value.name // Could be undefined!
// Good
const value = data.find(x => x.id === id)
if (value) {
value.name // Type-safe
}
// Or with optional chaining
const name = data.find(x => x.id === id)?.name
Type Inference When Obvious
// Redundant
const count: number = 5
const name: string = 'Portfolio Buddy'
// Better (TypeScript infers)
const count = 5
const name = 'Portfolio Buddy'
// Explicit when needed
const metrics: Metric[] = [] // Empty array needs type
Component Size Limits
Max 200 Lines Per Component
When component exceeds 200 lines:
- Extract sub-components
- Move logic to custom hooks
- Extract utilities to utils/
Current Violations
⚠️ MUST REFACTOR:
- PortfolioSection.tsx: 591 lines (295% of limit)
- Extract EquityChartSection
- Extract PortfolioStats
- Extract ContractControls
- Keep only orchestration logic
Should refactor:
- App.tsx: 351 lines (175% of limit)
- Extract sections into components
- MetricsTable.tsx: 242 lines (121% of limit)
- Improved from 350 lines, still over limit
Refactoring Example
// Before: 591 lines in PortfolioSection
function PortfolioSection() {
// Contract multiplier logic (50 lines)
// Date filtering logic (40 lines)
// Chart configuration (100 lines)
// Statistics calculation (80 lines)
// Rendering logic (300+ lines)
}
// After: Split into focused pieces
function PortfolioSection() {
const portfolio = usePortfolio(files, dateRange)
const contracts = useContractMultipliers(portfolio.strategies)
return (
<div>
<ContractControls {...contracts} />
<EquityChartSection data={portfolio.equity} />
<PortfolioStats metrics={portfolio.metrics} />
</div>
)
}
File Organization
Actual Directory Structure
src/
├── components/
│ └── [AllComponents].tsx (flat structure, no subdirs)
├── hooks/
│ ├── useContractMultipliers.ts
│ ├── useMetrics.ts
│ ├── usePortfolio.ts
│ └── useSorting.ts
├── utils/
│ └── dataUtils.ts (metric calculations, parsing)
├── App.tsx
└── main.tsx
Note: No ui/ or charts/ subdirectories - components are flat in components/
Naming Conventions
- Components: PascalCase -
MetricsTable.tsx,CorrelationHeatmap.tsx - Hooks: camelCase with
useprefix -useMetrics.ts,useSorting.ts - Utils: camelCase -
calculateMetrics(),parseCSV() - Types/Interfaces: PascalCase -
interface Metric,type Trade
Error Handling
Always Handle Errors
// Bad
const data = await supabase.storage.upload(file)
// Good
const { data, error } = await supaba
Установить coding-standards в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл coding-standards?
React 19 and TypeScript coding standards for Portfolio Buddy 2. Use when: writing new components, reviewing code, refactoring, or ensuring consistency. Contains component patterns, TypeScript rules, and best practices.
Как установить скилл coding-standards?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл coding-standards запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic