build(server): the test-mock and hand-built-service ratchets read code, not comments, and see the import() and alias forms

lint:test-mocks missed vi.mock(import('../src/config'), ...), the typed form Vitest takes, and counted mocks quoted in doc comments, which left slack a real mock could take. lint:test-new-service missed a service built under an import alias or as new (Name)(...). Both now strip comments first and recognise those forms; the baselines lose the entries that were only comments.
This commit is contained in:
Maurice
2026-10-10 19:56:54 +02:00
parent ef68c62d80
commit ac918d362f
6 changed files with 106 additions and 23 deletions
+37
View File
@@ -24,6 +24,43 @@ function walk(dir, files = []) {
return files;
}
/**
* The text with every // and /* comment blanked out (newlines kept, so line
* numbers hold), strings and template literals left as they are. A count
* that reads code, not prose, runs over this: a call quoted in a doc comment
* is not a call.
*/
export function stripComments(text) {
let out = '';
let i = 0;
while (i < text.length) {
const c = text[i];
const next = text[i + 1];
if (c === '/' && next === '/') {
const end = text.indexOf('\n', i);
i = end < 0 ? text.length : end;
continue;
}
if (c === '/' && next === '*') {
const end = text.indexOf('*/', i + 2);
const stop = end < 0 ? text.length : end + 2;
out += text.slice(i, stop).replace(/[^\n]/g, ' ');
i = stop;
continue;
}
if (c === '"' || c === "'" || c === '`') {
let j = i + 1;
while (j < text.length && text[j] !== c) j += text[j] === '\\' ? 2 : 1;
out += text.slice(i, j + 1);
i = j + 1;
continue;
}
out += c;
i++;
}
return out;
}
/** Counts keyed by the server-relative POSIX path, files without any left out. */
export function scan(serverDir, check) {
const dir = join(serverDir, check.root);