Imported from jimmypaolini/codebase (
.agents/skills/write-comments/SKILL.md). Install upstream withnpx skills add jimmypaolini/codebase --skill write-comments. Copyright stays with the author (MIT).
Commenting
When to Comment
Code should be self-explanatory through good naming. Comments add value only when they explain why something is done โ not what it does.
Comment when:
- Explaining non-obvious intent or business logic
- Documenting known edge cases or external constraints
- Noting a workaround with a link to the upstream issue
Don't comment when:
- The code is clear from reading it
- You're narrating what the code obviously does
How to Comment
Good Comments
// Delay is intentional: the third-party API enforces a 1s rate limit per key
await delay(1000);
// Uses linear search because this list is always < 10 items and never hot
const found = items.find((item) => item.id === targetId);
Bad Comments
// Increment counter
counter++;
// Call the API
const result = await fetchData();
// Return the value
return value;
Anti-Patterns
Obvious Comments
// Bad: restates what the code already says
const user = getUser(id); // Get the user by id
Redundant JSDoc
Avoid JSDoc on private functions or functions whose signature is self-documenting.
// Bad: JSDoc that adds nothing
/**
* Gets the user.
* @param id - The user id.
* @returns The user.
*/
function getUser(id: string): User { ... }
// Good: JSDoc only when it adds non-obvious context
/**
* Returns the user record, or throws `UserNotFoundError` if the id is
* not present in the active-users projection. Does NOT check the archive.
*/
function getUser(id: string): User { ... }
TODO Comments
Don't leave TODO comments to bypass lint rules or defer real fixes.
// Bad: silences a rule without explanation
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function process(data: any) { ... }
// Good: fix the underlying issue instead
function process(data: unknown) { ... }
If a TODO is genuinely needed (tracked work), include a ticket reference:
// TODO(#1234): remove once the upstream API supports batch deletes
Divider Comments
// Bad: dash dividers
// ---------------------------------------------------------------------------
// Configuration
// ---------------------------------------------------------------------------
// Bad: equals dividers
// ===========================
// Configuration
// ===========================
// Bad: plain section label with no emoji
// Configuration
// Bad: #region blocks
//#region ๐ง Configuration
//#endregion
Use emoji section comments instead โ see Section Comments below.
Section Comments
When a file benefits from logical groupings, mark each section with a single-line emoji comment.
Format
// <emoji> <Section name>
- Emoji first โ conveys purpose at a glance
- Capital first letter โ
// ๐ง Configuration, not// ๐ง configuration - Single line โ no closing marker, no surrounding dash lines
- Python uses
#instead of//โ same rules otherwise
Examples
TypeScript / JavaScript
// ๐ง Configuration
const MAX_RETRIES = 3;
const API_TIMEOUT = 5_000;
// ๐ญ Mocks
vi.mock("./api.js");
// ๐งช Tests
describe("MyService", () => { ... });
NestJS service layout
@Injectable()
export class MyService {
// ๐ Dependency injection
constructor(private readonly logger: LoggerService) {}
// ๐ Private fields
// ๐ Public fields
// ๐ Private methods
// ๐ Public methods
}
Python
# ๐ง Configuration
MAX_RETRIES = 3
# ๐งช Tests
class TestMyService(unittest.TestCase): ...
Emoji Reference
| Emoji | Typical use |
|---|---|
| ๐ | Dependency injection, constructors |
| ๐ง | Configuration, constants |
| ๐๏ธ | Types, data structures |
| ๐ท๏ธ | Type aliases, interfaces |
| โ๏ธ | Constants module |
| ๐ | Private fields |
| ๐ | Public fields |
| ๐ | Private methods |
| ๐ | Public methods |
| ๐ญ | Mocks |
| ๐งช | Tests |
| ๐ | Relations, associations, links |
| ๐ | Queries |
| ๐๏ธ | Mutations |
| ๐ | Headings, lists |
| ๐ฆ | Code blocks, packages |
| ๐ | Paragraphs, docs |
| ๐ผ๏ธ | Images |
| โ๏ธ | Inline formatting |
| โ | Completed / passing |
| โ | Thematic breaks |
| ๐ฌ | Blockquotes |
| ๐ | Tables |
| ๐ | Grammar groups, large topic areas |
Rules Summary
- Format:
// <emoji> <Section name>(TypeScript/JS) or# <emoji> <Section name>(Python) - Section name: capitalized first letter, short noun phrase
- Never wrap a section comment in dash lines or any other delimiter
- Never use
#region/#endregionโ plain emoji comments are sufficient - Choose an emoji that conveys the section's purpose; consult the table above