| name | write-comment |
| description | Use whenever writing or reviewing a code comment anywhere in this repo (lib, ext, spec, sig, docs, CI config, etc.) – e.g. "add a comment", "explain this in a comment", "is this comment worth keeping". Enforces dd-trace-rb comment-noise conventions. |
Writing code comments
Code comments
Default to no comment: a comment must earn its place by saying something the code cannot.
Exception: @public_api docstrings follow normal YARD conventions (@param, @return, @raise, @example, @see) — they're shipped customer docs (docs/PublicApi.md). The method body still follows the rules below. E.g.:
def baggage
Write a comment only when:
NEVER write:
Ratio check before finishing: if a diff has more than roughly one comment per 15 lines of new code, or if any comment would still be true after deleting the code it narrates, cut comments until that stops being the case. Exempt declaration-only blocks (struct/instance field docs with no accompanying logic) from the ratio — density there doesn't imply narration.
When editing existing files: don't add comments to code you merely moved or reformatted. Don't remove comments outside your change's scope unless they're now wrong — that's unrelated churn. Comments on code you're actually touching still follow the rules above.
Prefer over commenting: a clearer name, an extracted well-named function, a named constant instead of a literal, or a test that demonstrates the behavior.
Removing existing comments
Applies only to reviewing/deleting existing comments, not writing new ones:
- Fix the named defect, don't just delete. Rename the identifier (repetition), relocate to
sig/ (type restatement), add a shared reference (copy-paste) — apply it, or verify the destination already carries the information (e.g. the .rbs actually declares the type), before removing.
- A deletable comment can contain a keeper. Judge multi-line comments per line: delete the narration, keep an embedded hazard/why/citation line.
- A tag and its wrapped continuation are one unit. Remove both together, then re-read the docstring for a complete, consistent signature.
- Bulk sweeps hide repeated defects. One file or module per commit, so a systematic mistake surfaces on file one.
Style
Always be terse. One line beats a paragraph; a fragment beats a full sentence. E.g.:
not: