coding-standards
Official适用于TypeScript、JavaScript、React和Node.js开发的通用编码标准、最佳实践和模式。
What this skill does
When applied, it prepends a system prompt before your request is sent — no extra calls and no change to how you are billed beyond the added tokens.
---
name: coding-standards
description: 适用于TypeScript、JavaScript、React和Node.js开发的通用编码标准、最佳实践和模式。
origin: ECC
---
# 编码标准与最佳实践
适用于所有项目的通用编码标准。
## 何时激活
* 开始新项目或新模块时
* 审查代码质量和可维护性时
* 重构现有代码以遵循约定时
* 强制执行命名、格式或结构一致性时
* 设置代码检查、格式化或类型检查规则时
* 引导新贡献者熟悉编码规范时
## 代码质量原则
### 1. 可读性优先
* 代码被阅读的次数远多于被编写的次数
* 清晰的变量和函数名
* 优先选择自文档化代码,而非注释
* 一致的格式化
### 2. KISS (保持简单,傻瓜)
* 采用能工作的最简单方案
* 避免过度设计
* 不要过早优化
* 易于理解 > 聪明的代码
### 3. DRY (不要重复自己)
* 将通用逻辑提取到函数中
* 创建可复用的组件
* 跨模块共享工具函数
* 避免复制粘贴式编程
### 4. YAGNI (你不会需要它)
* 不要预先构建不需要的功能
* 避免推测性泛化
* 仅在需要时增加复杂性
* 从简单开始,需要时再重构
## TypeScript/JavaScript 标准
### 变量命名
```typescript
// PASS: GOOD: Descriptive names
const marketSearchQuery = 'election'
const isUserAuthenticated = true
const totalRevenue = 1000
// FAIL: BAD: Unclear names
const q = 'election'
const flag = true
const x = 1000
```
### 函数命名
```typescript
// PASS: GOOD: Verb-noun pattern
async function fetchMarketData(marketId: string) { }
function calculateSimilarity(a: number[], b: number[]) { }
function isValidEmail(email: string): boolean { }
// FAIL: BAD: Unclear or noun-only
async function market(id: string) { }
function similarity(a, b) { }
function email(e) { }
```
### 不可变性模式 (关键)
```typescript
// PASS: ALWAYS use spread operator
const updatedUser = {
...user,
name: 'New Name'
}
const updatedArray = [...items, newItem]
// FAIL: NEVER mutate directly
user.name = 'New Name' // BAD
items.push(newItem) // BAD
```
### 错误处理
```typescript
// PASS: GOOD: Comprehensive error handling
async function fetchData(url: string) {
try {
const response = await fetch(url)
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
}
return await response.json()
} catch (error) {
console.error('Fetch failed:', error)
throw new Error('Failed to fetch data')
}
}
// FAIL: BAD: No error handling
async function fetchData(url) {
const response = await fetch(url)
return response.json()
}
```
### Async/Await 最佳实践
``Use this skill
Add a "skill" field with the skill’s ID to your chat completion request. It is applied server-side before your prompt is sent — no extra calls.
{
"model": "gpt-4o-mini",
"skill": "imp-e1dce9d0-48d8-4e4b-9268-081c32d25cbd",
"messages": [{ "role": "user", "content": "…" }]
}Install the skill, enable it in your dashboard and (optionally) limit it to specific models. It then applies automatically to every matching request — with no "skill" field to send each time.
Set it up in your dashboardMore skills
Set up and use 1Password CLI for sign-in, desktop integration, and reading or injecting secrets.
Create, view, edit, delete, search, move, or export Apple Notes via the memo CLI on macOS.
List, add, edit, complete, or delete Apple Reminders and reminder lists via remindctl.
Create, search, and manage Bear notes via grizzly CLI.
Monitor blogs and RSS/Atom feeds for updates using the blogwatcher CLI.
BluOS CLI (blu) for discovery, playback, grouping, and volume.
Capture frames or clips from RTSP/ONVIF cameras.
Search, install, update, sync, or publish agent skills with the ClawHub CLI and registry.