|
|
|
@@ -108,22 +108,21 @@ How work proceeds in any repo, unless that repo's `AGENTS.md` says otherwise.
|
|
|
|
|
|
|
|
|
|
**Link, don't inline — and keep the link bare.** A mechanism identical across call sites or repos is documented once in the canonical source and pointed at with a one-line bare link; N copies drift, whether they are comments or READMEs. Don't summarize what's behind the link or restate the identifier's own name.
|
|
|
|
|
|
|
|
|
|
**A pointer is not a definition.** A definition the reader needs to follow the code — what a unit counts, what a term means, what invariant a cache rests on — sits at the code in one line. A pointer to it (`see AGENTS.md §11`) is the one comment form that cannot be checked against the code beside it, so it rots invisibly. A pointer carrying rationale — a rejected alternative, the premise behind a standing choice — is correct and stays.
|
|
|
|
|
**A pointer is not a definition.** A definition the reader needs to follow the code — what a unit counts, what a term means, what invariant a cache rests on — sits at the code. A pointer to it (`see AGENTS.md §11`) is the one comment form that cannot be checked against the code beside it, so it rots invisibly. A pointer carrying rationale — a rejected alternative, the premise behind a standing choice — is correct and stays.
|
|
|
|
|
|
|
|
|
|
### Comments
|
|
|
|
|
|
|
|
|
|
The rules below govern prose comments; doc comments a tool consumes — docstrings, godoc, JSDoc types — are outside them.
|
|
|
|
|
|
|
|
|
|
Default to NO comment. Delete one that is any of:
|
|
|
|
|
1. A **restatement** of the adjacent code. BANNED: `// Sanitized + bounded to 1000 chars` above `mb_substr(json_encode(LogSanitizer::body($x)), 0, 1000)`.
|
|
|
|
|
2. A **cross-cutting convention** used elsewhere (sanitization, the 1000-char Loki cap, "log so the source is recoverable"). Project-wide facts live in ONE doc, never repeated at call sites.
|
|
|
|
|
3. A **justification of self-evident code** (a log line is self-evidently for observing its value).
|
|
|
|
|
4. A **file preamble or arrangement rationale**: what a file holds, why it exists, why two things share it, why a check sits beside what it judges, why an order was chosen. The file name and the declarations are the index; a choice with no effect on the running program belongs in the commit that made it.
|
|
|
|
|
|
|
|
|
|
**One line is the default; a paragraph is rare and has to be argued for.** A second line is a signal to stop and ask where this really belongs — nearly always the commit message or the ticket. Consecutive comment lines are the specific defect this rule exists to stop: they are how a file reaches 40% prose. A placement argument is not a length argument. A paragraph occasionally IS right — a genuinely subtle invariant a reader must hold before touching the code below, which stays with the code it guards. What earns it is an invariant, never a rationale.
|
|
|
|
|
**What stays is one terse line, and only where the code cannot show it.** GOOD: `# Pinned to 7.x: hurl 8's jsonpath change breaks the nth-filter asserts.` A second line belongs in the commit message or the ticket. The one exception is a paragraph for an invariant a reader must hold before touching the code below; it stays with the code it guards.
|
|
|
|
|
|
|
|
|
|
**A plausible "why" is not enough on its own.** Multi-line background explaining what a thing is for, or how we got here, piles up into walls a few lines of code cannot justify. Keep a comment only where it stops a real mistake or records an external constraint the code can't show, and then as ONE terse line. When unsure, delete. GOOD: `# Pinned to 7.x: hurl 8's jsonpath change breaks the nth-filter asserts.`
|
|
|
|
|
|
|
|
|
|
**No file preambles, and no rationale for how code is arranged.** A file gets no header comment saying what it holds, why it exists, or why it sits where it does — the file name and the declarations are the index. Nor may a comment explain why two things share a file, why a check lives beside what it judges, or why an order was chosen: that choice has no effect on the running program and belongs in the commit that made it, or in the decision record. Structured doc comments a tool consumes (docstrings, godoc, JSDoc types) are not the target; prose narration is.
|
|
|
|
|
|
|
|
|
|
**Density is a review signal.** Set the tooling-consumed doc comments aside, then count: prose comment lines much past ~10% of a file's remaining non-blank lines mean something is wrong — narrating comments, or code that fails to carry its own meaning. A defect to investigate, not a style preference.
|
|
|
|
|
**Density is a review signal.** Prose comment lines much past ~10% of a file's non-blank lines mean something is wrong — narrating comments, or code that fails to carry its own meaning. A defect to investigate, not a style preference.
|
|
|
|
|
|
|
|
|
|
### README
|
|
|
|
|
|
|
|
|
|