Skip to content

Commit 787cb70

Browse files
Programcodeclaude
andcommitted
fix(lint): keep dollar-quoted bodies and nest block comments when blanking SQL
Codex review of 1e354ba: `$$/*$$` opened a false comment that hid later checks, and a nested block comment ended at its first `*/`. Dollar-quoted bodies are now copied as-is (calls inside them are still checked), and block comments track depth. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 1e354ba commit 787cb70

1 file changed

Lines changed: 34 additions & 16 deletions

File tree

‎scripts/check-repo-rules.mjs‎

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,49 @@ function checkWorkflows() {
6868
}
6969
}
7070

71-
// Replaces SQL comments with spaces, keeping newlines and string literals,
72-
// so comments can neither supply nor hide a call's arguments.
71+
// Replaces SQL comments with spaces, keeping newlines, quoted strings and
72+
// dollar-quoted bodies, so comments can neither supply nor hide a call's
73+
// arguments. Block comments nest, as in PostgreSQL.
7374
function blankComments(source) {
7475
let out = "";
7576
let index = 0;
77+
const copyUntil = (stop) => {
78+
out += source.slice(index, stop);
79+
index = stop;
80+
};
81+
const blankUntil = (stop) => {
82+
out += source.slice(index, stop).replace(/[^\n]/g, " ");
83+
index = stop;
84+
};
7685
while (index < source.length) {
77-
const char = source[index];
78-
if (char === "'") {
86+
const dollar = source.slice(index).match(/^\$[A-Za-z_]*\$/);
87+
if (source[index] === "'") {
7988
const end = source.indexOf("'", index + 1);
80-
const stop = end === -1 ? source.length : end + 1;
81-
out += source.slice(index, stop);
82-
index = stop;
89+
copyUntil(end === -1 ? source.length : end + 1);
90+
} else if (dollar) {
91+
const end = source.indexOf(dollar[0], index + dollar[0].length);
92+
copyUntil(end === -1 ? source.length : end + dollar[0].length);
8393
} else if (source.startsWith("--", index)) {
8494
const end = source.indexOf("\n", index);
85-
const stop = end === -1 ? source.length : end;
86-
out += " ".repeat(stop - index);
87-
index = stop;
95+
blankUntil(end === -1 ? source.length : end);
8896
} else if (source.startsWith("/*", index)) {
89-
const end = source.indexOf("*/", index + 2);
90-
const stop = end === -1 ? source.length : end + 2;
91-
out += source.slice(index, stop).replace(/[^\n]/g, " ");
92-
index = stop;
97+
let depth = 0;
98+
let stop = index;
99+
while (stop < source.length) {
100+
if (source.startsWith("/*", stop)) {
101+
depth += 1;
102+
stop += 2;
103+
} else if (source.startsWith("*/", stop)) {
104+
depth -= 1;
105+
stop += 2;
106+
if (depth === 0) break;
107+
} else {
108+
stop += 1;
109+
}
110+
}
111+
blankUntil(stop);
93112
} else {
94-
out += char;
95-
index += 1;
113+
copyUntil(index + 1);
96114
}
97115
}
98116
return out;

0 commit comments

Comments
 (0)