Skip to content

docs: write comments for the next reader, not the reviewer - #347

Merged
oekazuma merged 1 commit into
mainfrom
claude/trim-comments
Aug 2, 2026
Merged

oekazuma merged 1 commit into
mainfrom
claude/trim-comments

Conversation

@oekazuma

@oekazuma oekazuma commented Aug 2, 2026 •

Copy link
Copy Markdown
Owner

Comments added over the last few PRs had drifted into arguing decisions — text aimed at whoever was reviewing at the time, rather than at whoever opens the file next.

packages/cli/src/cli-io.ts was the clearest specimen: six lines of doc comment on a two-method interface, ending with

The two are structurally identical, so TypeScript would not have flagged them drifting apart.

which explains why the refactor was worth doing — and which the commit message already said. Every future reader pays for that sentence; the commit is read once.

The rule applied

A comment earns its place only when it says something the code cannot: a constraint, a rejected alternative and why, or a non-local dependency. Rationale for a change goes in the commit message and the PR. Test names state the behaviour, not the reasoning.

Before / after on the same interface:

// before — 6 lines
/**
 * The output sink for the read-only subcommands (`docs`, `explain`). Narrower than the install
 * wizard's `InstallIO` — neither touches the filesystem — and shared so that a change to how
 * subcommands emit lines (a `warn` channel, stripping color off a non-TTY) is one edit rather
 * than one per subcommand. The two are structurally identical, so TypeScript would not have
 * flagged them drifting apart.
 */

// after — 1 line, nothing lost
/** Output sink for the read-only subcommands. Narrower than `InstallIO` — no filesystem access. */

Test names got the same treatment — it('says the topics ship with the CLI, which is the reason to prefer them over a web search') became it('says the topics match the running version').

Result

Before After
src/cli-io.ts comment ratio 50% 11%
src/docs/cli.ts comment ratio 16% 4%
scripts/docs-embed.mjs comment ratio 35% 15%
Bundled docs (packages/cli/docs/*.md) 2251 words 2072 words

87 lines net removed across 15 files. No topic dropped from the bundled docs, no assertion dropped from a test, no behaviour change.

Comments that survived are the ones carrying real information — why the staleness test compares content rather than rendered text (oxfmt reformats the generated module), why string-map cannot say "never replaces" (it is a spread, unlike string-list), why the frontmatter reader rejects quotes (the sibling reader in scripts/rules-index.mjs unquotes, and the two must not disagree).

Also

Recorded the rule in AGENTS.md under Conventions, so it applies to future sessions rather than living only in this PR.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Clarified CI workflow behavior, including pull request analysis, outputs, failures, permissions, and fork handling.
    • Improved guidance for configuration, monorepo detection, reporters, scoping, exit codes, and CLI usage.
    • Added conventions for concise, constraint-focused comments and documentation.
  • Tests

    • Updated test descriptions and coverage to reflect current documentation, CLI commands, and guidance.
    • Confirmed use of svelte-vitals explain instead of the removed MCP tool.

The comments added over the last few PRs had drifted into arguing decisions —
text that belongs in a commit message, read once, rather than in a file read
every time. `cli-io.ts` was the clearest case: six lines of doc comment on a
two-method interface, ending in a sentence explaining why the refactor was
worth doing, which the commit already said.

Applied one rule throughout: a comment earns its place only when it says
something the code cannot — a constraint, a rejected alternative and why, a
non-local dependency. Test names state the behaviour, not the reasoning.

87 lines net removed. Comment ratio: cli-io.ts 50% -> 11%, docs/cli.ts 16% ->
4%, docs-embed.mjs 35% -> 15%. Bundled docs 2251 -> 2072 words with no topic
dropped. No behaviour change — every check still passes.

Recorded in AGENTS.md so it holds for future sessions too.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ee047691-abb7-4bb3-b89b-c903a62f1235

📥 Commits

Reviewing files that changed from the base of the PR and between e70eb0a and 344e9a7.

📒 Files selected for processing (15)
  • AGENTS.md
  • packages/cli/docs/ci.md
  • packages/cli/docs/config.md
  • packages/cli/docs/monorepo.md
  • packages/cli/docs/output.md
  • packages/cli/docs/scoping.md
  • packages/cli/scripts/docs-embed.mjs
  • packages/cli/src/cli-io.ts
  • packages/cli/src/docs/cli.ts
  • packages/cli/src/docs/generated.ts
  • packages/cli/src/explain.ts
  • packages/cli/test/docs-cli.test.ts
  • packages/cli/test/docs-embed.test.mjs
  • packages/cli/test/explain.test.ts
  • packages/cli/test/install/skill-content.test.ts

📝 Walkthrough

Walkthrough

The PR updates CLI documentation, generated documentation, source comments, and test descriptions. It clarifies documented behavior and adds checks for runnable documentation commands. Runtime logic and public declarations remain unchanged.

Changes

CLI documentation and comment cleanup

Layer / File(s) Summary
CLI documentation content
packages/cli/docs/*, packages/cli/src/docs/generated.ts
The documentation clarifies workflow, configuration, monorepo, output, scoping, suppression, and exit-code behavior.
Source comments and generated-file guidance
AGENTS.md, packages/cli/scripts/docs-embed.mjs, packages/cli/src/cli-io.ts, packages/cli/src/docs/cli.ts, packages/cli/src/explain.ts
Comments and generated-file instructions are shortened and focused on behavior or constraints.
CLI test descriptions and skill checks
packages/cli/test/docs-cli.test.ts, packages/cli/test/docs-embed.test.mjs, packages/cli/test/explain.test.ts, packages/cli/test/install/skill-content.test.ts
Test descriptions and comments are simplified. Skill-content tests verify complete documentation commands and current explain guidance.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: revising comments to serve future readers rather than explain rationale to reviewers.
Docstring Coverage ✅ Passed Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@oekazuma
oekazuma merged commit 86fd7cc into main Aug 2, 2026
8 checks passed
@oekazuma
oekazuma deleted the claude/trim-comments branch August 2, 2026 10:04
oekazuma added a commit that referenced this pull request Aug 2, 2026
The candidate list appended extensions unconditionally, so an import written
`from '$lib/server/store.js'` — how a NodeNext/ESM TypeScript project spells an
import of its own `.ts` source — produced `store.js.ts` and `store.js.js`,
matched nothing, and left the write unarbitrated. Verified as a real miss
against a fixture before fixing.

A path already carrying an extension is now checked as written, and a `.js` one
is then remapped to `.ts`. Extensionless paths are unchanged. A client imported
the same way still resolves and stays exempt.

Also from review: a test was named after why it exists rather than what it
verifies, which is the AGENTS.md rule added in #347, and the changeset had an
ungrammatical sentence.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
oekazuma added a commit that referenced this pull request Aug 2, 2026
* fix(core): report a hand-rolled in-memory store under $lib/server

Closes #354.

`security/handler-state-write` exempts `.set()`/`.update()` on imports resolving
under the `$lib` server root — that is where database and KV clients live, and
`db.set(…)` on one is persistence, not shared state. The check was purely
path-based, so a plain `new Map()` in the same directory was exempt too, which
is exactly the shape that serves one user's data to the next.

The call shape cannot separate the two, and the pure parse cannot read another
file, so arbitration moves to the collector, which has the Runtime:
`parseKitModuleFacts` records the deferred write with the resolved path and the
exported name, and `collectKitModuleFacts` reads the target module and promotes
only the writes whose export is an in-memory container.

Precision-first, like the rest of this default-on rule. An export initialized to
`new Map`/`Set`/`WeakMap`/`WeakSet` or to an object/array literal is reported;
anything else — a client built from a package import, a re-export, a module that
cannot be found or read — stays exempt, so what the read cannot positively
identify is silence rather than a false positive.

Only the modules a handler actually writes to are read, asserted by a test, so a
project whose handlers never touch `$lib/server` does no extra I/O. Aliased
imports resolve through the exported name. Property writes were already reported
everywhere and are untouched. Both the CLI and the Vite plugin go through the
same collector, so both gain this.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(core): resolve a NodeNext `.js` specifier to its TypeScript source

The candidate list appended extensions unconditionally, so an import written
`from '$lib/server/store.js'` — how a NodeNext/ESM TypeScript project spells an
import of its own `.ts` source — produced `store.js.ts` and `store.js.js`,
matched nothing, and left the write unarbitrated. Verified as a real miss
against a fixture before fixing.

A path already carrying an extension is now checked as written, and a `.js` one
is then remapped to `.ts`. Extensionless paths are unchanged. A client imported
the same way still resolves and stays exempt.

Also from review: a test was named after why it exists rather than what it
verifies, which is the AGENTS.md rule added in #347, and the changeset had an
ungrammatical sentence.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant