From DingLan研发标准
团队约定的 Node.js(JavaScript / TypeScript)代码命名规范。**任何时候**为本团队/项目编写、审查、重构 JavaScript 或 TypeScript 代码时都必须使用,包括但不限于:声明变量/常量/布尔值、定义函数或方法、命名类与接口、创建源代码文件。即使用户没有明确提到"命名规范"或"代码规范",只要在写或改 JS/TS 代码就要套用这套规则。
How this skill is triggered — by the user, by Claude, or both
Slash command
/engineering-standards:dl-naming-conventionsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
本规范覆盖 Node.js 下的 JavaScript 与 TypeScript 代码。
本规范覆盖 Node.js 下的 JavaScript 与 TypeScript 代码。
写代码前先按这个顺序自检:变量 → 函数/方法 → 类/接口 → 文件名。缩写词大小写(见第 5 节)贯穿所有元素。
camelCase小写字母开头,多单词驼峰拼接。
const userName = "John";
let userAge = 25;
UPPER_SNAKE_CASE全大写 + 下划线分隔,仅用于真正不变的值。
const MAX_RETRY_COUNT = 3;
const DEFAULT_TIMEOUT_MS = 5000;
只有"真正不变的字面量"才用全大写;像
const user = fetchUser()这种引用绑定仍然用 camelCase。
is / has / should 开头读起来像一个判断句。
const isActive = true;
const hasPermission = false;
const shouldRetry = true;
存放多个元素的变量用复数,读代码时一眼能看出它是集合。
const users = await fetchUsers();
const orderIds = orders.map((o) => o.id);
需要强调底层数据结构时可加后缀(
userList、idSet),但默认优先用复数名词。
函数名直接说明"它做了什么"。
function getUserById(id: number): User { /* ... */ }
function calculateTotalPrice(items: Item[]): number { /* ... */ }
function sendNotification(userId: number, message: string): void { /* ... */ }
常用动词参考:get / set / fetch / create / update / delete / validate / parse / format / handle / build。
_ 开头类的私有方法以 _ 开头。TS 里同时加 private 修饰符。
class UserService {
private _validateInput(input: string): void { /* ... */ }
}
PascalCase每个单词首字母大写。描述具体实体(User、Order)或行为载体(UserService、OrderValidator)。
class UserService { /* ... */ }
class OrderValidator { /* ... */ }
PascalCase,无 I 前缀接口名描述行为或结构本身。
interface User {
id: number;
name: string;
}
interface UserRepository {
findById(id: number): Promise<User | null>;
}
文件名用 kebab-case + 功能后缀,或主导出类用 PascalCase:
user.controller.ts // 控制器
auth.module.ts // 模块
order.service.ts // 服务
user-repository.ts // 仓储(多单词用 kebab-case)
UserEntity.ts // 主要导出一个同名类时,文件名与类同名
选择原则:
PascalCase 与类名一致kebab-case 加后缀ID、URL、HTTP、API、DB 等缩写词一律当作普通单词处理:只大写首字母,其余小写,不要整体大写。这条规则贯穿变量、函数、类、文件名。
const userId = 1; // ✅ 不是 userID
const httpClient = createClient(); // ✅ 不是 HTTPClient
function parseUrl(raw: string): URL { /* ... */ } // ✅ 不是 parseURL
class HttpRequest { /* ... */ } // ✅ 不是 HTTPRequest
唯一例外:缩写词出现在常量里时,跟随
UPPER_SNAKE_CASE,如DEFAULT_API_TIMEOUT_MS、MAX_URL_LENGTH。
| 元素 | 风格 | 示例 |
|---|---|---|
| 变量 | camelCase | userName |
| 常量 | UPPER_SNAKE_CASE | MAX_RETRY_COUNT |
| 布尔 | is/has/should 前缀 | isActive |
| 集合/数组 | 复数名词 | users |
| 函数/方法 | 动词+名词 camelCase | getUserById |
| 私有方法 | _ 前缀 | _validateInput |
| 类 | PascalCase | UserService |
| 接口 | PascalCase,无 I 前缀 | UserRepository |
| 文件名 | kebab-case + 后缀 或 PascalCase | user.controller.ts |
| 缩写词 | 仅首字母大写 | userId httpClient |
应用本规范后,逐项确认:
camelCase,所有常量是 UPPER_SNAKE_CASEis / has / should 开头_ 前缀开头(TS 同时加 private)PascalCase,接口没有 I 前缀kebab-case + 后缀 或 PascalCase 规则users 而非 userList,除非要强调结构)userId 而非 userID,HttpRequest 而非 HTTPRequest)npx claudepluginhub dinglantechnology/engineering-standards --plugin engineering-standardsSearches MemPalace before answering questions about past work, people, projects, or prior decisions. Returns verbatim stored content instead of guessing from model memory.
Guides Payload CMS config (payload.config.ts), collections, fields, hooks, access control, APIs. Debugs validation errors, security, relationships, queries, transactions, hook behavior.
Implements vector databases with Pinecone, Weaviate, Qdrant, Milvus, pgvector for semantic search, RAG, recommendations, and similarity systems. Optimizes embeddings, indexing, and hybrid search.