Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(ci): add compact mode to rust comment stripper

Steven Enamakel2b08a5c01988
diff --git a/scripts/ci/check-crate-chain.mjs b/scripts/ci/check-crate-chain.mjs
index 1a2d21e701..c5cde96963 100644
--- a/scripts/ci/check-crate-chain.mjs
+++ b/scripts/ci/check-crate-chain.mjs
@@ -127,12 +127,13 @@ export const HOST_RPC_INTERNAL_PATTERNS = [
* Blank out Rust comments and string literals (contents only), keeping line
* structure, so a banned path quoted in a doc, log message or fixture is not
* mistaken for code. Handles nested block comments, escapes and raw strings.
- * Optional literal preservation supports type signatures; default masking is unchanged.
+ * Optional literal preservation and code-whitespace compaction support type
+ * signatures; default masking is unchanged. Compaction leaves literal contents intact.
*/
-export function stripRustComments(text, { preserveLiterals = false } = {}) {
+export function stripRustComments(text, { preserveLiterals = false, compact = false } = {}) {
let out = '';
let i = 0;
- const blank = chunk => chunk.replace(/[^\n]/g, ' ');
+ const blank = chunk => compact ? '' : chunk.replace(/[^\n]/g, ' ');
while (i < text.length) {
const rest = text.slice(i);
let m;
@@ -171,7 +172,7 @@ export function stripRustComments(text, { preserveLiterals = false } = {}) {
out += preserveLiterals ? text.slice(i, j + 1) : blank(text.slice(i, j + 1));
i = j + 1;
} else {
- out += text[i];
+ if (!compact || !/\s/.test(text[i])) out += text[i];
i++;
}
}
diff --git a/scripts/ci/check-process-statics.mjs b/scripts/ci/check-process-statics.mjs
index e268247089..8281ef3de4 100644
--- a/scripts/ci/check-process-statics.mjs
+++ b/scripts/ci/check-process-statics.mjs
@@ -18,7 +18,6 @@ const signature = (entry) =>
/** Source declarations only: includes aliases and lazy_static!, not macro expansion. */
export function declarations(text, file) {
const code = stripRustComments(text);
- const signatureCode = stripRustComments(text, { preserveLiterals: true });
const found = [];
const pattern =
/(?<!')\bstatic\s+(?:(mut|ref)\s+)?((?:r#)?[_\p{ID_Start}][_\p{ID_Continue}]*)\s*:(?!:)/gu;
@@ -50,7 +49,10 @@ export function declarations(text, file) {
}
if (end === code.length)
throw new Error(`${file}: cannot parse static ${match[2]}`);
- const type = signatureCode.slice(start, end).replace(/\s+/g, "");
+ const type = stripRustComments(text.slice(start, end), {
+ preserveLiterals: true,
+ compact: true,
+ });
if (!type) throw new Error(`${file}: static ${match[2]} has no type`);
found.push({
file,