Patterns / The "... existing code ..." placeholder
The "... existing code ..." placeholder
Chat assistants show partial files with placeholder comments so they don't have to repeat unchanged code. When that output gets pasted or applied by an agent, the placeholder can replace the real code it was standing in for. The diff looks small and tidy, and a whole function quietly disappears.
What it looks like
// ... existing code ... // rest of the implementation stays the same # ... previous methods unchanged ... // add your business logic here /* implementation goes here */
Why it matters
It's the single most damaging habit of chat-based code generation, because the deletion is hidden. Reviewers read the new lines and assume the comment is a note, not a replacement. Tests catch it only if they cover the code that vanished.
Before and after
export function applyDiscount(cart) {
// ... existing validation ...
return cart.total * 0.9;
}export function applyDiscount(cart) {
if (!cart.items.length) throw new Error("empty cart");
if (cart.total < 0) throw new Error("negative total");
return cart.total * 0.9;
}How to fix it
- Fail the build on placeholder comments in added lines (SlopScore for Code treats this as an error).
- When applying AI edits, ask for complete functions, or apply edits as patches that preserve unchanged lines.
- Check the PR's deleted lines: a placeholder plus a large deletion is the giveaway.
When it's fine
A literal ellipsis in a docstring example or a comment like '// ...' inside a code sample in documentation. SlopScore for Code skips docstrings and bare '...' comments.
placeholder-code) and 11 others. Score a public PR or add the free GitHub Action.