Skip to content

Commit b69903a

Browse files
authored
Add code comment instructions (#63306)
1 parent 4190788 commit b69903a

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

‎.github/instructions/code.instructions.md‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ applyTo: "src/**,.github/**,config/**,.devcontainer/**,**Dockerfile,package*.jso
44

55
# Copilot code instructions for docs.github.com
66

7-
For code reviews and for creating or updating pull requests, follow the Guidelines, Tests, and Validate sections below.
7+
For code reviews and for creating or updating pull requests, follow the guidelines in the sections below.
88

99
## Guidelines
1010

@@ -101,3 +101,27 @@ logger.error("Failure", { error });
101101
- Never log secrets, tokens, or PII.
102102
- Create loggers once at module scope, not inside functions.
103103
- Do not use the logger in scripts (locally-run code); `console.log` is fine there.
104+
105+
## Code comments
106+
107+
- Comments explain _why_ and not _what_. Use variables, names, types, and structure to convey _what_ the code does. If the code doesn't need a _why_, don't write a comment.
108+
- Document constraints, workarounds, unexpected dependencies, domain rules, user-visible consequences, security, ordering, and performance issues.
109+
- Be concise. Keep the comment to a glance.
110+
- Use active voice and active, specific verbs. Avoid phrases like "there is", "should", or vague "uses". Prefer "does x" over "is x". Do not hedge. If needed, write the action then the reason, such as "do X, so Y".
111+
- Do not narrate, restate, or summarize the code.
112+
- Avoid jargon, or define jargon if you must use it.
113+
- Describe the current state. Avoid framing such as "now" or "recently". Do not include the previous state.
114+
- In TypeScript and JavaScript, prefer `//` over `/*` comments. Only use `/*` if `//` makes the formatting too awkward or in JSX. Do not use JSDoc or TSDoc style comments.
115+
- Do not use comments to add headings, dividers, steps, or other structures.
116+
- Comments that need more than one line: break at sentence ends and clauses. Prettier does not reflow comment format.
117+
- Avoid excessive formatting. Only use parentheses to refer to literal syntax. Do not use markdown-style formatting. Do not use emdashes. You may use uppercase to emphasize words, rarely.
118+
- Keep comments inside a function body to a single line. Place multiline comments above the function.
119+
- Do not reference issues, pull requests, or discussions in the `github` organization, such as numbers or URLs. Include the context directly in the comment or in a nearby markdown file. You may use a full URL to an issue in an external open source project.
120+
- Do not reference line numbers or line counts. Do not reference specific versions unless a future version requires action.
121+
- Do not leave TODO, FIXME, or HACK comments.
122+
- Do not keep commented out code.
123+
- You may label deliberately absent fields.
124+
- You may write a simple input and output example for regular expressions. Use realistic data and not garbage like foo/bar or Alice/Bob.
125+
- You may use internal cross-reference identifiers in comments, such as unique error codes.
126+
- You may use tool directives such as `@ts-expect-error` or `eslint-disable` in rare cases.
127+
- You may add legally required comments like license and copyright.

0 commit comments

Comments
 (0)