Code Commenting and Maintainability
Activation scope
Use this skill when a task:
- adds, changes, reviews, or removes source-code comments;
- changes behavior near an existing comment;
- adds or reviews JSDoc/TSDoc, TODO/FIXME notes, test-plan headers, or structured file documentation;
- introduces non-obvious business rules, permissions, security assumptions, ordering, concurrency, rollback, compatibility behavior, or workarounds;
- requires deciding whether code should be simplified instead of commented.
Also follow the relevant domain skill for frontend, validation, database, test, review, and Git rules.
Core rule
Comments should make non-obvious intent clear. They should not narrate code that is already readable.
Prefer clearer names, smaller functions, or simpler control flow before adding a comment. Add a comment only when a future maintainer would otherwise miss an important reason, boundary, or tradeoff.
Language
Use plain Vietnamese for comments in project-owned code and tests when comments are needed.
Keep English when required by:
- public API or tooling conventions;
- third-party examples or generated code;
- surrounding file conventions;
- exact identifiers, API names, SQL names, type names, library names, and domain terms such as
SSOT, TOEIC, MVP, Zod, Supabase, Server Action, RPC, and RLS.
Do not mix English and Vietnamese just to make a comment sound more technical.
Good reasons to comment
Comments are appropriate for:
- non-obvious business rules;
- RLS, security, auth, role, or ownership assumptions;
- migration order, backfill, existing-data safety, and database integrity constraints;
- concurrency, race-condition, idempotency, retry, rollback, or stale-response behavior;
- tricky edge cases where the safe behavior is not obvious from the code;
- external service constraints, such as Supabase, PayOS, Vercel, CI, browser APIs, uploads, or webhooks;
- intentional tradeoffs or compatibility behavior;
- test intent, unusual fixtures, hostile-client simulation, or non-trivial test-plan reasoning.
Useful:
// Giữ question có group_id hỏng để bước readiness báo lỗi sửa được,
// thay vì lọc mất dữ liệu và làm khóa học trông như hợp lệ.
Useful:
-- Backfill trước khi thêm NOT NULL để migration chạy được trên database đã có dữ liệu.
What not to comment
Do not add comments that merely repeat:
- assignments;
- ordinary
if conditions;
- clear
map, filter, or reduce operations;
safeParse or routine validation calls;
- early returns;
- obvious function calls;
- ordinary database queries;
- self-explanatory issue codes;
- arrange/act/assert test structure;
- syntax that is already clear from nearby names and types.
Avoid:
// Lọc các chapter còn hoạt động.
const activeChapters = chapters.filter(isActive);
The code already says that.
Comment placement
Prefer the highest useful level:
- Use a short file-level comment only when the file's responsibility is not obvious.
- Use a few phase comments in a long function only when they make the flow easier to scan.
- Use local comments only for unusual decisions or hidden constraints.
- Use one shared comment for adjacent schemas, helpers, or checks that share the same rule.
Do not comment every export, helper, branch, loop, query, or schema field.
JSDoc and TSDoc
Do not add public API, JSDoc, or TSDoc comments mechanically.
Use them only when:
- an exported or shared utility has a contract callers can easily misuse;
- TypeScript cannot express an important guarantee, limitation, or side effect clearly;
- tooling requires the comment.
Keep routine implementation comments as normal inline comments, not JSDoc.
TODO and FIXME
A TODO/FIXME must state:
- the concrete missing work or defect;
- why it cannot be completed now;
- the blocker, follow-up, or integration point;
- a searchable task or issue reference when available.
Avoid:
// TODO: fix later
Prefer:
// TODO: thay adapter mock bằng Server Action khi endpoint review tồn tại;
// hiện tại không được hiển thị success giả.
Remove TODO/FIXME notes when the condition no longer exists.
Test-plan headers
Preserve the test-quality-strategy convention: non-trivial test files need a concise Vietnamese test-plan header when that skill requires it.
The header may be longer than ordinary comments because it documents test intent, covered behavior, verification status, and known gaps. Keep it accurate and update it when cases or verification change.
Review workflow
When reviewing or editing comments:
- Read the code without the comment and decide what is genuinely hard to infer.
- Remove comments that repeat names, conditions, issue codes, or syntax.
- Keep or add comments for hidden constraints, business rules, security boundaries, data integrity, concurrency, external service limits, and meaningful test intent.
- Rewrite vague or buzzword-heavy prose into plain Vietnamese where possible.
- Confirm every remaining comment matches the current code and tests.
- Inspect the final diff for stale, duplicated, contradictory, or overly dense comments.
Scope control
Update comments directly affected by the task.
Report misleading comments outside scope instead of silently doing a repository-wide cleanup.
Do not introduce unrelated refactors while improving comments.
Final checklist
1---2name: code-commenting-and-maintainability3description: General code-comment quality and maintainability rules for VocaSpace/DevSpace. Use when adding, changing, reviewing, or removing source-code comments, JSDoc/TSDoc, TODO/FIXME notes, test-plan headers, or explanations of non-obvious implementation behavior.4---56# Code Commenting and Maintainability78## Activation scope910Use this skill when a task:1112* adds, changes, reviews, or removes source-code comments;13* changes behavior near an existing comment;14* adds or reviews JSDoc/TSDoc, TODO/FIXME notes, test-plan headers, or structured file documentation;15* introduces non-obvious business rules, permissions, security assumptions, ordering, concurrency, rollback, compatibility behavior, or workarounds;16* requires deciding whether code should be simplified instead of commented.1718Also follow the relevant domain skill for frontend, validation, database, test, review, and Git rules.1920## Core rule2122Comments should make non-obvious intent clear. They should not narrate code that is already readable.2324Prefer clearer names, smaller functions, or simpler control flow before adding a comment. Add a comment only when a future maintainer would otherwise miss an important reason, boundary, or tradeoff.2526## Language2728Use plain Vietnamese for comments in project-owned code and tests when comments are needed.2930Keep English when required by:3132* public API or tooling conventions;33* third-party examples or generated code;34* surrounding file conventions;35* exact identifiers, API names, SQL names, type names, library names, and domain terms such as `SSOT`, `TOEIC`, `MVP`, `Zod`, `Supabase`, `Server Action`, `RPC`, and `RLS`.3637Do not mix English and Vietnamese just to make a comment sound more technical.3839## Good reasons to comment4041Comments are appropriate for:4243* non-obvious business rules;44* RLS, security, auth, role, or ownership assumptions;45* migration order, backfill, existing-data safety, and database integrity constraints;46* concurrency, race-condition, idempotency, retry, rollback, or stale-response behavior;47* tricky edge cases where the safe behavior is not obvious from the code;48* external service constraints, such as Supabase, PayOS, Vercel, CI, browser APIs, uploads, or webhooks;49* intentional tradeoffs or compatibility behavior;50* test intent, unusual fixtures, hostile-client simulation, or non-trivial test-plan reasoning.5152Useful:5354```ts55// Giữ question có group_id hỏng để bước readiness báo lỗi sửa được,56// thay vì lọc mất dữ liệu và làm khóa học trông như hợp lệ.57```5859Useful:6061```sql62-- Backfill trước khi thêm NOT NULL để migration chạy được trên database đã có dữ liệu.63```6465## What not to comment6667Do not add comments that merely repeat:6869* assignments;70* ordinary `if` conditions;71* clear `map`, `filter`, or `reduce` operations;72* `safeParse` or routine validation calls;73* early returns;74* obvious function calls;75* ordinary database queries;76* self-explanatory issue codes;77* arrange/act/assert test structure;78* syntax that is already clear from nearby names and types.7980Avoid:8182```ts83// Lọc các chapter còn hoạt động.84const activeChapters = chapters.filter(isActive);85```8687The code already says that.8889## Comment placement9091Prefer the highest useful level:9293* Use a short file-level comment only when the file's responsibility is not obvious.94* Use a few phase comments in a long function only when they make the flow easier to scan.95* Use local comments only for unusual decisions or hidden constraints.96* Use one shared comment for adjacent schemas, helpers, or checks that share the same rule.9798Do not comment every export, helper, branch, loop, query, or schema field.99100## JSDoc and TSDoc101102Do not add public API, JSDoc, or TSDoc comments mechanically.103104Use them only when:105106* an exported or shared utility has a contract callers can easily misuse;107* TypeScript cannot express an important guarantee, limitation, or side effect clearly;108* tooling requires the comment.109110Keep routine implementation comments as normal inline comments, not JSDoc.111112## TODO and FIXME113114A TODO/FIXME must state:115116* the concrete missing work or defect;117* why it cannot be completed now;118* the blocker, follow-up, or integration point;119* a searchable task or issue reference when available.120121Avoid:122123```ts124// TODO: fix later125```126127Prefer:128129```ts130// TODO: thay adapter mock bằng Server Action khi endpoint review tồn tại;131// hiện tại không được hiển thị success giả.132```133134Remove TODO/FIXME notes when the condition no longer exists.135136## Test-plan headers137138Preserve the `test-quality-strategy` convention: non-trivial test files need a concise Vietnamese test-plan header when that skill requires it.139140The header may be longer than ordinary comments because it documents test intent, covered behavior, verification status, and known gaps. Keep it accurate and update it when cases or verification change.141142## Review workflow143144When reviewing or editing comments:1451461. Read the code without the comment and decide what is genuinely hard to infer.1472. Remove comments that repeat names, conditions, issue codes, or syntax.1483. Keep or add comments for hidden constraints, business rules, security boundaries, data integrity, concurrency, external service limits, and meaningful test intent.1494. Rewrite vague or buzzword-heavy prose into plain Vietnamese where possible.1505. Confirm every remaining comment matches the current code and tests.1516. Inspect the final diff for stale, duplicated, contradictory, or overly dense comments.152153## Scope control154155Update comments directly affected by the task.156157Report misleading comments outside scope instead of silently doing a repository-wide cleanup.158159Do not introduce unrelated refactors while improving comments.160161## Final checklist162163* [ ] Comments use Vietnamese where project conventions allow it164* [ ] Comments explain why, boundary, risk, or intent rather than obvious syntax165* [ ] No noisy comments were added166* [ ] JSDoc/TSDoc is limited to genuinely useful exported/shared contracts or tooling needs167* [ ] TODO/FIXME notes are actionable168* [ ] Required test-plan headers remain accurate169* [ ] Comments match current behavior170* [ ] No unrelated cleanup was introduced