Use these rules when the user requests documentation or comments for a file.
Your ONLY task is to add comments. You are strictly forbidden from changing the code implementation.
- Safety First: If adding a comment to a complex line (like nested ternaries) risks breaking syntax, SKIP THE COMMENT.
- Preservation: You must preserve the code structure exactly.
- Do NOT fix bugs.
- Do NOT reformat lines (Prettier/ESLint).
- Do NOT change variable names.
DO NOT place JSX comments immediately after ternary : operators.
This pattern ALWAYS BREAKS:
) : (
{/* This breaks - placed right after colon */}
<Component />
)The parser expects an expression (like <Component />), not a comment. If you need to comment, use one of these safe alternatives:
- Comment BEFORE the ternary (preferred)
- Comment INSIDE a wrapper element (if unavoidable)
- SKIP the comment (safest if in doubt)
Before outputting code, you must internally verify:
- Brackets: Do all
{,(, and[have matching closing counterparts? - JSX: Are all
<div>and components properly closed? - Ternaries: Did you accidentally break a
?or:operator? - Post-Colon Comments: Did you place any
{/* */}immediately after a:in a ternary? (INVALID - remove it) - Comment Context: Is every JSX comment
{/* */}inside a JSX element or wrapped in parentheses?
- Syntax: Inside any
return (...)or JSX block, you must ONLY use{/* comment */}. - Forbidden: NEVER use
//inside JSX. It will render as text or break the parser.
This is the most common cause of errors. Follow this strictly:
-
External Comments Only: Do NOT try to insert comments inside the
?or:branches unless they are large blocks. -
CRITICAL: Never place a JSX comment
{/* */}immediately after a ternary:operator or right before its expression. -
Best Practice: Place the comment ABOVE the start of the ternary condition.
- DO:
{ /* Show loading state if fetching, otherwise show list */ } { isLoading ? <Loading /> : <List />; }
- DON'T (Breaks Code):
{ isLoading ? ( // check loading <Loading /> // else ) : ( <List /> ); }
- ALSO DON'T (Breaks Code - Post-Colon Comments):
{ condition ? ( <ComponentA /> ) : ( {/* This comment breaks syntax - placed right after colon */} <ComponentB /> ) }
WHY THIS FAILS: The parser expects an expression after
:, not a JSX comment block. The{/* */}is not a valid expression in this context.- CORRECT Alternative (Comments Inside Container):
{ condition ? ( <ComponentA /> ) : ( <div> {/* Safe comment inside JSX element */} <ComponentB /> </div> ); }
- Check Active Chat: Review the current chat history first.
- File Lookup: Only read the parent component file if the prop context is missing from the chat AND entirely unclear.
- Goal: Explain where data comes from (e.g., "Passed from DashboardContainer").
Add a specific one-liner comment before every logical block:
- Functions: What it handles.
- State: What data is stored.
- Effects: Trigger and result.
- Logic:
&&,||, andifstatements. - Props: Origin and usage.
- Imports: Do NOT add comments for imports.
- Getters/Setters: Do NOT comment inside simple one-line objects.
Safe JSX Commenting: return (
{/* Content Area: Renders list or empty state based on data */}
{hasData ? (
<List items={items} />
) : (
<EmptyState />
)}
Safe Logic Commenting: // Calculate user permission level based on role and parent props const canEdit = user.role === 'admin' || parentProps.allowEdit;