{"slug":"writing-comments","title":"writing-comments","summary":"How to write JSDoc (/** */) and inline (//) comments in the Astro codebase, for contributors reading the source — not end users. Use whenever writing or editing comments in .ts/.js source, including comments added incidentally while fixing bugs or building features. Does not cove","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-09-20T08:01:13.09453Z","repo":{"url":"https://github.com/modem-dev/ossrules","stars":56,"forks":2,"license":"MIT","updatedAt":"2026-09-21T14:36:48Z"},"bodyHtml":"<hr>\n<h2>name: writing-comments\ndescription: How to write JSDoc (/** */) and inline (//) comments in the Astro codebase, for contributors reading the source — not end users. Use whenever writing or editing comments in .ts/.js source, including comments added incidentally while fixing bugs or building features. Does not cover the @docs-generated config/error reference.</h2>\n<h1>Writing Comments</h1>\n<h2>Purpose</h2>\n<p>Comments in this repository are read by contributors, months or years after\nthey were written, with none of the context you have right now. This skill\ndefines who that reader is, what each kind of comment is for, and which patterns\nare banned.</p>\n<h2>Scope Boundary</h2>\n<p>This skill governs <strong>contributor-facing</strong> comments in the TypeScript/JavaScript\nsource. It does <strong>not</strong> apply to end-user documentation:</p>\n<ul>\n<li>JSDoc blocks tagged <code>@docs</code> in\n<a href=\"../../../packages/astro/src/types/public/config.ts\"><code>packages/astro/src/types/public/config.ts</code></a>\nand\n<a href=\"../../../packages/astro/src/core/errors/errors-data.ts\"><code>packages/astro/src/core/errors/errors-data.ts</code></a>\nare scraped by an external <code>docgen</code> tool and published to the Astro docs\nwebsite. Follow\n<a href=\"../../../packages/astro/src/core/errors/README.md\"><code>packages/astro/src/core/errors/README.md</code></a>\nfor those, and get docs-team review — CI regenerates the reference when\n<code>types/public/**</code> changes.</li>\n<li>Other JSDoc across <code>types/public/**</code> is surfaced to users through editor\nIntelliSense. Write it for Astro <strong>users</strong> building a site, not for\ncontributors reading the source.</li>\n</ul>\n<p>Everything below is about the source a contributor reads at HEAD.</p>\n<h2>The Reader</h2>\n<p>Write for an Astro contributor who is competent in TypeScript but has <strong>no\naccess to your current context</strong>: not this conversation, not the pull request,\nnot the issue, not the diff. They see only the repository at HEAD.</p>\n<p>Two consequences follow directly:</p>\n<ol>\n<li><strong>Never narrate change history.</strong> Words like \"now\", \"previously\", \"no\nlonger\", \"the new approach\" are meaningless at HEAD, where only one approach\nexists. State how the code works, not how it came to be. (A <code>@deprecated</code>\nnotice is the exception — see <a href=\"#conventions-in-this-codebase\">Conventions</a> —\nbecause it describes the contract's future, which the reader needs.)</li>\n<li><strong>Never address the reviewer.</strong> A comment that argues your change is correct\n(\"this properly handles X\") belongs in the PR description, not in the source.\nThe comment must justify the code as it stands, permanently.</li>\n</ol>\n<h2>Three Kinds of Comments, Three Different Jobs</h2>\n<table>\n<thead>\n<tr>\n<th>Kind</th>\n<th>Syntax</th>\n<th>Job</th>\n<th>Contains</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>File / module overview</td>\n<td><code>/** */</code> at the top of the file</td>\n<td>Explanation</td>\n<td>Why the module exists, the concepts and terms it defines, how the pieces relate, design rationale</td>\n</tr>\n<tr>\n<td>Item docs</td>\n<td><code>/** */</code> directly above a declaration</td>\n<td>Reference</td>\n<td>The contract: behavior, parameters, return value, thrown errors, invariants. Neutral and factual</td>\n</tr>\n<tr>\n<td>Inline comments</td>\n<td><code>//</code> inside a body</td>\n<td>Rationale</td>\n<td>Only what the code cannot say: constraints, workarounds (with issue links), non-obvious coupling</td>\n</tr>\n</tbody>\n</table>\n<p>Do not mix the jobs. Implementation details do not belong in the <code>/** */</code>\ncontract — put them as <code>//</code> comments inside the body. The contract does not\nbelong scattered across inline comments — put it on the declaration.</p>\n<h2>The Deletion Test</h2>\n<p>Before writing any comment, ask: <strong>does this state something the reader cannot\nrecover from the code itself?</strong></p>\n<ul>\n<li>If the information is already carried by names, types, or structure, do not\nwrite the comment. If the name fails to carry it, improve the name.</li>\n<li>Information that legitimately needs a comment: an invariant, a rationale, a\ncoupling to code elsewhere, a workaround with a link, surprising behavior of a\ndependency, a term of art the module defines.</li>\n</ul>\n<p>When editing later, the same test applies in reverse: a comment that no longer\npasses it should be deleted, not left to rot.</p>\n<h2>Link to the Issue for Workarounds</h2>\n<p>This codebase consistently anchors workarounds to a source. Any comment that\nexplains a workaround, a <code>HACK</code>, a regression guard, or surprising behavior of a\ndependency <strong>must link the GitHub issue or PR</strong> that motivates it. The link is\nwhat lets a future reader tell whether the workaround is still needed.</p>\n<pre><code>// Handle recommended nanostores. Only @nanostores/preact is required from our testing!\n// Full explanation and related bug report: https://github.com/withastro/astro/pull/3667\n'@nanostores/preact',\n</code></pre>\n<p>A workaround with no link is indistinguishable from a mistake.</p>\n<h2>Banned Patterns</h2>\n<p><strong>Narrating the next line.</strong> Delete these on sight:</p>\n<pre><code>// Increment the generation counter\ngeneration += 1;\n</code></pre>\n<p><strong>Change-history narration.</strong> Rewrite as present-tense rationale:</p>\n<pre><code>// BAD: We now resolve lightningcss from the user's root instead of ours.\n// GOOD: lightningcss is an optional peer dep, so it resolves from the user's project root.\n</code></pre>\n<p><strong>Reviewer-addressed justification.</strong> Move the argument to the PR:</p>\n<pre><code>// BAD: This correctly handles the multi-encoded path from the bug report.\n// GOOD: A path still encoded after MAX_DECODE_ITERATIONS is rejected, so\n//       middleware and routing can never disagree on the decoded path.\n</code></pre>\n<p><strong>Restated JSDoc.</strong> A <code>/** */</code> block that rewords the declaration name says nothing:</p>\n<pre><code>// BAD:\n/** Compiles the styles. */\nfunction compileStyles(...)\n\n// GOOD:\n/** Rewrites relative `url()` references in `css` against `base`, leaving\n *  absolute and data URLs untouched. */\nfunction compileStyles(...)\n</code></pre>\n<p><strong>Vague hedging.</strong> \"Some cases\", \"various reasons\", \"handles edge cases\",\n\"etc.\" — either name them or drop the sentence.</p>\n<p><strong>Emojis.</strong> Banned in source, comments included (repo-wide policy).</p>\n<p><strong>Ad-hoc section banners</strong> (<code>// ----- helpers -----</code>, <code>// ==== TYPES ====</code>).\nThis codebase has no <code>// #region</code> folding convention; do not add banners. If a\nfile is long enough that you reach for one, that is a signal to split the file,\nnot to decorate it.</p>\n<h2>Conventions in This Codebase</h2>\n<p><strong>JSDoc tags.</strong> <code>@param name - description</code>, <code>@returns</code>, and <code>@throws</code> state the\ncontract. Brace-wrap a type (<code>@returns {Promise&lt;string&gt;}</code>) only when the\nsignature alone is ambiguous. Use <code>@example</code> with a fenced <code>```js</code> block for\nnon-obvious usage.</p>\n<p><strong>Cross-references.</strong> Use <code>{@link Symbol}</code> / <code>{@linkcode Symbol}</code> rather than a\nbare name, so a rename updates the reference and editors can jump to the target.</p>\n<p><strong><code>@internal</code>.</strong> Marks API that is not part of the public surface. It is a\nconvention only — there is no typedoc or api-extractor here to strip it — so it\ndocuments intent but does not replace access modifiers.</p>\n<p><strong><code>@deprecated</code>.</strong> State the migration, then the removal horizon:</p>\n<pre><code>/** @deprecated Use the instance method `cookies.consume()` instead. This will be removed in Astro 7 */\n</code></pre>\n<p>Say what to use instead, not merely that the symbol is deprecated. This\nfuture-tense note is contract information the reader needs, not banned\nchange-history narration.</p>\n<p><strong>TODO.</strong> Use <code>// TODO:</code> for deferred work; link an issue when one tracks it.\nFor work gated on a breaking-change window, use the established idiom\n<code>// TODO: remove in Astro &lt;N&gt;</code>. There is no <code>FIXME</code> in this codebase — do not\nintroduce it.</p>\n<h2>Editing Existing Code</h2>\n<ul>\n<li>Preserve existing comments. If your change alters behavior, extend or correct\nthe specific prose — never replace it with generic text. Deleting hard-won\ncontext is worse than leaving a comment slightly stale.</li>\n<li>When your change makes a comment false, fix it in the same diff. A stale\ncomment is worse than none.</li>\n<li>Match the surrounding density. A heavily documented module deserves the same\nlevel on new items; do not blanket a sparse module with comments.</li>\n</ul>\n<h2>Self-Check Before Finishing</h2>\n<p>After completing any task that touched comments, re-read <strong>only the comments in\nyour diff</strong>, in isolation from the code changes:</p>\n<ol>\n<li>Does each one pass the deletion test?</li>\n<li>Does any reference the conversation, the change itself, or the reviewer?</li>\n<li>Does every workaround link its issue or PR?</li>\n<li>Would a reader without access to the diff understand each one?</li>\n</ol>\n<p>Fix or delete what fails. Deletion is the default; a missing comment is cheaper\nthan a misleading one.</p>\n<h2>References</h2>\n<ul>\n<li><a href=\"https://diataxis.fr/\">Diátaxis</a> — the framework behind the explanation /\nreference / rationale split above.</li>\n<li><a href=\"../../../packages/astro/src/core/errors/README.md\"><code>packages/astro/src/core/errors/README.md</code></a>\n— for <code>@docs</code>-tagged error entries, which are end-user documentation.</li>\n<li><a href=\"https://tsdoc.org/\">TSDoc</a> — the tag reference for TypeScript doc comments.</li>\n</ul>\n","files":[{"path":"SKILL.md","sizeBytes":8981,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-09-20T08:02:40.969436Z","sha256":"BC6841C6649E488A8FE100B997AAF44E664E98EB3A249A463215234B302BFCC6","sizeBytes":4070},"review":null,"source":{"repositoryUrl":"https://github.com/modem-dev/ossrules","path":"public/files/astro/.agents/skills/writing-comments","license":"MIT","commit":"9625409b6c20077e1d92909e15e800608a85a776","subtreeSha":"E38FB1CE878DD9810BC883DBF4ED6ABB64C5DC351E868A3FBFC9D96EE94DB5D9","lastSyncedAt":"2026-09-27T20:55:30.018946Z"},"reviewedAt":"2026-09-20T08:09:10.643269Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/modem-dev/ossrules/tree/main/public/files/astro/.agents/skills/writing-comments"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install modem-dev-ossrules@llmmart"},{"target":"git","command":"git clone https://github.com/modem-dev/ossrules.git"}]}