| name | rule-code-comments |
| description | When and how to write effective comments — favor self-documenting code |
Rule code-comments
Apply this rule whenever work touches:
Comment guidelines for the schemas package
Well-named schemas and types are the primary documentation. Comments supplement when the code alone cannot convey intent, constraints, or domain knowledge.
Self-documenting code first
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?
const parsedData = parseInput(data);
const mr = 3;
const maxRetries = 3;
const parsedInput = parseInput(data);
Explain WHY, not WHAT
When a comment is necessary, it should explain the reason behind a decision — not narrate the code.
if (weight_kg > 0) { ... }
if (weight_kg > 0) { ... }
const LocationSchema = z.strictObject({ ... });
const LocationSchema = z.strictObject({ ... });
Domain and business context
Schema libraries encode business rules. Document the domain knowledge that future developers will not find in the code.
const AdministrativeDivisionCodeSchema = z
.string()
.regex(/^[A-Z]{2}-[A-Z0-9]+$/);
const MassIDAttributesSchema = z.array(AttributeSchema).max(17);
TSDoc for exported symbols
Use TSDoc (/** ... */) sparingly — only for exported symbols where the name and type signature are insufficient.
export function uniqueBy<T extends z.ZodTypeAny, K>(
schema: T,
selector: (item: z.infer<T>) => K,
errorMessage?: string,
) { ... }
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.
Commented-out code
Never commit commented-out code. Use version control to retrieve old code. If code is temporarily disabled, use a clear mechanism:
const ENABLE_EXTENDED_VALIDATION = false;
TODO comments
TODOs must include context and a tracking reference. Bare TODOs are not acceptable.
Zod .meta() as documentation
In this project, .meta() is a form of documentation. Use it to document fields instead of inline comments:
external_id: ExternalIdSchema,
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.