Skip to content

Commit 377ba65

Browse files
fix(enrichment): restrict print() debug detection to Python paths
Avoid false positives on method calls like document.print(). Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e57c7c3 commit 377ba65

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

review-enrichment/src/analyzers/debug-leftover.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ const CONSOLE_RE = /\bconsole\s*\.\s*(?:log|debug|info|warn|error|trace|dir|tabl
1515
const PRINT_RE = /\bprint\s*\(/;
1616

1717
/** Classify one added line for a debug leftover, or null. Pure. */
18-
export function detectDebugLeftover(line: string): DebugLeftoverFinding["kind"] | null {
18+
export function detectDebugLeftover(
19+
line: string,
20+
path?: string,
21+
): DebugLeftoverFinding["kind"] | null {
1922
const code = codeOnly(line);
2023
if (DEBUGGER_RE.test(code)) return "debugger";
2124
if (CONSOLE_RE.test(code)) return "console";
22-
if (PRINT_RE.test(code)) return "print";
25+
// Python-only: `\bprint` after a dot would false-positive on `document.print()` / `obj.print()`.
26+
if (path && /\.pyi?$/i.test(path) && PRINT_RE.test(code)) return "print";
2327
return null;
2428
}
2529

@@ -51,7 +55,7 @@ export function scanPatchForDebugLeftover(
5155
if (line.startsWith("+")) {
5256
const body = line.slice(1);
5357
if (body.length <= MAX_LINE_CHARS) {
54-
const kind = detectDebugLeftover(body);
58+
const kind = detectDebugLeftover(body, path);
5559
if (kind) {
5660
findings.push({ file: path, line: newLine, kind });
5761
if (findings.length >= maxFindings) return findings;

review-enrichment/test/debug-leftover.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ test("detectDebugLeftover: recognizes debugger, console sinks, and print()", ()
1616
assert.equal(detectDebugLeftover(" debugger;"), "debugger");
1717
assert.equal(detectDebugLeftover("console.log('hi')"), "console");
1818
assert.equal(detectDebugLeftover(" console.debug(state)"), "console");
19-
assert.equal(detectDebugLeftover("print('debug')"), "print");
19+
assert.equal(detectDebugLeftover("print('debug')", "lib/b.py"), "print");
20+
});
21+
22+
test("detectDebugLeftover: print() is Python-only and does not match method calls like document.print()", () => {
23+
assert.equal(detectDebugLeftover("document.print()"), null);
24+
assert.equal(detectDebugLeftover("printer.print('x')"), null);
25+
assert.equal(detectDebugLeftover("print('debug')", "src/widget.ts"), null);
2026
});
2127

2228
test("detectDebugLeftover: a console call inside a string literal is not flagged", () => {

0 commit comments

Comments
 (0)