1 # Comment Writing Guidelines
2
3 ## Tone
4
5 - Be **concise** — avoid long explanations. State what's needed and why, nothing more.
6 - Be **supportive** — acknowledge the contributor's effort, especially for community PRs.
7 - Be **specific** — when requesting changes, list exactly what needs to change. Never say "this needs improvement" without explaining how.
8 - Use "we" when speaking on behalf of the Medusa team.
9 - Avoid filler phrases like "Great work!", "Awesome PR!" — just get to the point.
10
11 ## Initial Approval Comment Template
12
13 Use when the PR passes the review. The team still needs to do a final review before merging.
14
15 ```
16 Thank you for your contribution, @<author>! 🎉
17
18 After an initial review, this PR looks good to us. Here's a summary:
19
20 ✅ PR template is complete
21 ✅ Linked to a verified issue
22 ✅ Follows contribution guidelines
23 ✅ Tests included
24 ✅ Follows Medusa's conventions
25
26 A team member will do a final review before this is merged. We appreciate your patience!
27 ```
28
29 Adjust the checklist to only include items that were actually verified. Omit items not applicable.
30
31 If there are **minor notes** that aren't blocking (style suggestions, optional improvements), add them as a separate "Notes" section after the summary — but still apply `initial-approval`.
32
33 ## Requires-More Comment Template
34
35 Use when the PR needs changes. Be explicit about what is required.
36
37 ```
38 Thank you for your contribution, @<author>!
39
40 After reviewing this PR, we need a few things addressed before we can move forward:
41
42 **Required changes:**
43 - [ ] <specific change 1>
44 - [ ] <specific change 2>
45
46 <Optional: brief explanation of why each change is needed>
47
48 <Include one or more of the sections below when applicable — omit sections that have nothing to report>
49
50 **Security Issues:**
51
52 🔒 **`path/to/file.ts`** — <vulnerability class>
53 ```typescript
54 // problematic snippet
55 ```
56 <Attack scenario + fix>
57
58 **Performance Issues:**
59
60 ⚡ **`path/to/file.ts`** — <issue description>
61 ```typescript
62 // problematic snippet
63 ```
64 <Impact + fix>
65
66 **Potential Bugs:**
67
68 ⚠️ **`path/to/file.ts`** — <bug description>
69 ```typescript
70 // problematic snippet
71 ```
72 <Why it fails + fix>
73 ```
74
75 **Rules for the required changes list:**
76 - Each item must be actionable — the contributor should know exactly what to do
77 - Reference specific files or line numbers when relevant
78 - Group related items together
79 - Security issues and blocking performance issues **must** appear in Required changes AND in their dedicated section with code snippets
80
81 ## Contextual Assessment
82
83 Before composing the review, assess whether the changes make sense in the broader context of the PR. This goes beyond checking conventions — it evaluates whether the implementation is sound and complete.
84
85 **Ask yourself:**
86
87 - **Is the behavior being changed intentional and documented?** If the PR modifies existing behavior, check whether that behavior is described as by design in the official Medusa documentation (`www/apps/book/app/learn/`). If the docs explicitly describe the current behavior as intentional, the PR is changing intended behavior and must be flagged as `requires-more`. Explain that the behavior is by design and reference the documentation section. This is a **blocking** concern — do not apply `initial-approval`.
88 - **Does it make sense?** Does the implementation actually solve the problem described in the PR or linked issue? Is the approach reasonable, or is there a simpler/safer way?
89 - **Are there unintended side effects?** Could the change break or alter behaviour in other areas of the codebase? For example: shared utilities, middleware, event handlers, or widely-used types.
90 - **Is the scope right?** Does the PR do more or less than what the linked issue asks for? Extra unrelated changes are a flag.
91 - **Is anything missing?** Could the change cause regressions that aren't covered by the added tests? Are edge cases handled?
92 - **Are there obvious performance or correctness concerns?** For example: N+1 queries, missing null checks, incorrect error handling.
93
94 If concerns are found, include them in the review comment under a **"Concerns"** section (for `requires-more`) or a **"Notes"** section (for `initial-approval` if non-blocking):
95
96 ```
97 **Concerns:**
98 - <specific concern and which file/area it affects>
99 - <another concern>
100 ```
101
102 Keep concerns concise and factual — describe the problem, not a lecture. If unsure whether something is actually a bug, phrase it as a question: *"Should `X` also handle the case where `Y` is null?"*
103
104 ## Potential Bugs Section
105
106 When bugs are found in Step 12, include a **"Potential Bugs"** section in the review comment. **All bugs — confirmed or suspected — are required changes.** Always apply `requires-more` when this section is present.
107
108 **Format:**
109
110 ```
111 **Potential Bugs:**
112
113 ⚠️ **`path/to/file.ts`** — <one-line description of the bug>
114 ```typescript
115 // the problematic snippet
116 ```
117 <Specific failure scenario — "this will throw if `items` is empty", not "this looks wrong". Suggest the fix.>
118
119 ⚠️ **`path/to/other-file.ts`** — <another bug>
120 ...
121 ```
122
123 **Rules:**
124 - Every bug goes into **Required changes** as a checkbox item AND in this section with the code snippet
125 - Always quote the relevant code snippet in a fenced code block
126 - Be specific about the failure scenario
127 - If uncertain, phrase as a question (*"Should this handle the case where X is undefined?"*) but still list it as a required change — the author must confirm or disprove it
128 - Do not flag style issues or code smell — only correctness/runtime concerns
129
130 ## Security Issues Section
131
132 When security issues are found in Step 10, include a **"Security Issues"** section in the review comment.
133
134 - Confirmed security vulnerabilities → add to **Required changes** and always apply `requires-more`
135 - Suspected / uncertain risks → include under **"Security Issues"** with a question framing
136
137 **Format:**
138
139 ```
140 **Security Issues:**
141
142 🔒 **`path/to/file.ts`** — <vulnerability class, e.g., "Missing authorization check">
143 ```typescript
144 // the problematic snippet
145 ```
146 <Explain the attack scenario in one sentence. What can an attacker do? What data is exposed or operation is possible? Suggest the fix.>
147
148 🔒 **`path/to/file.ts`** — <another issue>
149 ...
150 ```
151
152 **Rules:**
153 - Always name the vulnerability class (e.g., "SQL injection", "Missing auth", "Path traversal", "SSRF", "Sensitive data exposure")
154 - Always include the relevant code snippet in a fenced code block
155 - Describe the concrete attack scenario — *"an authenticated user could access another store's orders by passing a different `store_id`"* not *"this looks insecure"*
156 - If unsure, phrase as a question: *"Should this route require `isAdmin` middleware?"*
157 - Security issues are always **blocking** — do not apply `initial-approval` with a security issue in the Notes section
158
159 ## Performance Issues Section
160
161 When performance issues are found in Step 11, include a **"Performance Issues"** section in the review comment.
162
163 - Blocking performance issues (N+1 queries, unbounded queries on large tables, missing pagination) → add to **Required changes** and apply `requires-more`
164 - Non-blocking performance observations → include under **"Performance Issues"** as notes only
165
166 **Format:**
167
168 ```
169 **Performance Issues:**
170
171 ⚡ **`path/to/file.ts`** — <one-line description, e.g., "N+1 query inside order item loop">
172 ```typescript
173 // the problematic snippet
174 ```
175 <Explain why this is a problem in production terms — e.g., "for a cart with 50 items, this executes 50 separate DB queries instead of one". Suggest the fix — e.g., "batch-load with `findMany({ where: { id: In(ids) } })` before the loop".>
176
177 ⚡ **`path/to/file.ts`** — <another issue>
178 ...
179 ```
180
181 **Rules:**
182 - Always include the relevant code snippet in a fenced code block
183 - Quantify the impact where possible — *"N queries for N items"*, *"no LIMIT means entire table is fetched"*
184 - Suggest a concrete fix
185 - Do not flag theoretical micro-optimizations — only issues that would plausibly cause measurable degradation
186
187 ## Security Risk Comment Template (non-malicious, simple case)
188
189 Use for a single, brief security concern when no full Security Issues section is needed:
190
191 ```
192 **Security note:** <brief description of the potential risk and which file/change introduces it>
193
194 This may be unintentional, but please double-check and address it.
195 ```
196
197 ## Malicious Code Comment Template
198
199 Use only when closing a PR for malicious content. Be clear but not accusatory.
200
201 ```
202 We've closed this PR because it contains code that poses a security risk to users of Medusa.
203
204 If you believe this was a mistake, please open a new issue to discuss.
205 ```
206
207 ## Formatting Rules
208
209 - Use `**bold**` for section headers within comments
210 - Use checkboxes (`- [ ]`) for required action items
211 - Use inline code for file paths, variable names, and labels
212 - Use **fenced code blocks** (not inline code) when quoting or referencing actual code from the PR — e.g., a function body, a condition, or a snippet being flagged
213 - Keep paragraphs short — no walls of text
214 - Do not use headers (`##`) in short comments; use bold instead