基于 SOC 职业分类
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/carrot-foundation/schemas --skill rule-code-comments命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
Schema version injection, $id format, and SCHEMA_VERSION environment variable
Generated JSON Schema structure — required fields, validation patterns, and $ref usage
Use when a task is complete and needs the full check, commit, and PR workflow
| name | rule-code-comments |
| description | When and how to write effective comments — favor self-documenting code |
Apply this rule whenever work touches:
src/**/*.tsWell-named schemas and types are the primary documentation. Comments supplement when the code alone cannot convey intent, constraints, or domain knowledge.
The best comment is no comment. If you feel the need to add a comment, first ask: can I rename this variable, function, or type to make the comment unnecessary?
// BAD: comment restates what the code does
// Parse the input data
const parsedData = parseInput(data);
// BAD: comment explains a cryptic name
// Maximum number of retries
const mr = 3;
// GOOD: name is self-documenting
const maxRetries = 3;
const parsedInput = parseInput(data);
When a comment is necessary, it should explain the reason behind a decision — not narrate the code.
// BAD: restates the code
// Check if weight is greater than zero
if (weight_kg > 0) { ... }
// GOOD: explains domain constraint
// Negative weights indicate measurement errors and must be rejected
// per methodology rule MR-2024-003
if (weight_kg > 0) { ... }
// BAD: obvious comment
// Create a strict object schema
const LocationSchema = z.strictObject({ ... });
// GOOD: explains non-obvious design decision
// strictObject prevents extra properties from silently passing validation,
// which is critical for IPFS data integrity — any extra field would
// change the content hash
const LocationSchema = z.strictObject({ ... });
Schema libraries encode business rules. Document the domain knowledge that future developers will not find in the code.
// GOOD: domain context that cannot be inferred from code
// ISO 3166-2 subdivision codes (e.g., "BR-SP" for Sao Paulo, Brazil).
// Required by the MassID methodology for geographic attribution of
// waste collection impact.
const AdministrativeDivisionCodeSchema = z
.string()
.regex(/^[A-Z]{2}-[A-Z0-9]+$/);
// GOOD: explains constraint origin
// Maximum 17 attributes enforced by the smart contract's mint function.
// Adding more requires a contract upgrade.
const MassIDAttributesSchema = z.array(AttributeSchema).max(17);
Use TSDoc (/** ... */) sparingly — only for exported symbols where the name and type signature are insufficient.
// GOOD: TSDoc adds value for a utility with non-obvious behavior
/**
* Creates a Zod schema that validates array items are unique by a selector.
* Uses Set-based comparison for uniqueness checking.
*
* @param schema - The Zod schema for individual array items
* @param selector - Function to extract the uniqueness key from each item
* @param errorMessage - Custom error message for duplicate violations
*/
export function uniqueBy<T extends z.ZodTypeAny, K>(
schema: T,
selector: (item: z.infer<T>) => K,
errorMessage?: string,
) { ... }
// BAD: TSDoc adds no value — name and types are clear
/**
* The MassID data schema.
* Validates MassID data objects.
* @type {z.ZodObject}
*/
export const MassIDDataSchema = z.strictObject({ ... });
Skip TSDoc entirely when the export name, type signature, and .meta() already communicate everything. Schema exports with good .meta() titles and descriptions rarely need additional TSDoc.
Never commit commented-out code. Use version control to retrieve old code. If code is temporarily disabled, use a clear mechanism:
// BAD: dead code polluting the file
// const OldSchema = z.object({
// legacy_field: z.string(),
// });
// ACCEPTABLE: feature flag with tracking
// TODO(SCHEMAS-456): re-enable after v2 migration
const ENABLE_EXTENDED_VALIDATION = false;
TODOs must include context and a tracking reference. Bare TODOs are not acceptable.
// BAD: no context, no tracking
// TODO: fix this
// BAD: context but no tracking
// TODO: handle edge case for empty arrays
// GOOD: context + tracking reference
// TODO(SCHEMAS-789): add validation for negative coordinates
// after methodology team confirms the constraint rules
// GOOD: context + owner for short-term items
// TODO(@username): extract to shared utility before merging
.meta() as documentationIn this project, .meta() is a form of documentation. Use it to document fields instead of inline comments:
// BAD: comment next to field
// The UUID identifier for external system references
external_id: ExternalIdSchema,
// GOOD: meta serves as structured documentation
external_id: ExternalIdSchema.meta({
title: 'External ID',
description: 'UUID identifier for external system references',
}),
This approach generates documentation automatically via JSON Schema output, making it more useful than static comments.