chore(utils): migrate to shared random/ID utilities and add enforcement linting#4623
Conversation
…nt linting - Replace all Math.random(), crypto.randomUUID(), crypto.randomBytes(), nanoid, and uuid usages with shared @sim/utils/random and @sim/utils/id helpers across 72 files - Add new @sim/utils exports: deepClone, omit, filterUndefined (object), truncate (string), backoffWithJitter, parseRetryAfter (retry), getErrorMessage (errors) - Sweep all getErrorMessage, sleep, deepClone callsites across 500+ files to use shared utilities - Add Biome noRestrictedImports rule to catch nanoid, uuid, and crypto named imports at lint time - Add scripts/check-utils-enforcement.ts to catch Math.random and crypto.* global property access - Add check:utils script to package.json
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Also removes local Reviewed by Cursor Bugbot for commit cbbf972. Configure here. |
deepClone() was a one-line wrapper around structuredClone(), which is universally available in Node 17+ and all modern browsers. Removing the abstraction reduces indirection and means contributors don't need to learn a project-specific name for a well-known built-in. - Remove deepClone from packages/utils/src/object.ts and index.ts - Replace all 17 call sites with structuredClone() directly - Update check:utils script suggestion text - Update CLAUDE.md and global.md docs
…uncate docs - Add noRestrictedImports to biome.json under style — bans nanoid and uuid package imports at lint time (crypto.randomUUID/randomBytes are caught by the check:utils grep script which handles global property access) - Correct truncate() TSDoc and parameter name: sliceLength makes it clear that total output length is sliceLength + suffix.length, matching the behavior all callers were already written to expect
The sweep agents added getErrorMessage calls without the corresponding import in 4 files, causing test failures. Added the missing imports.
|
@greptile |
|
@cursor review |
…Turbopack issue - Fix retry.ts cross-file import: Turbopack cannot resolve './random.js' for internal package imports; inline the jitter crypto call directly - Add missing getErrorMessage imports to 32 files where the sweep added calls without the corresponding import (caught by type-check and test runs) - Remove accidental getErrorMessage import from crowdstrike/query/route.ts which has its own domain-specific getErrorMessage for parsing CrowdStrike's JSON error format - Fix use-sub-block-value.ts type error from structuredClone narrowing: add 'as T' cast at emitValue callsite (safe — valueCopy is always a structural copy of newValue)
…etErrorMessage The catch block was calling the local getErrorMessage function which parses CrowdStrike API JSON responses, not JavaScript Error objects. Use toError(error).message to correctly extract the message from a caught value in this context.
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit cbbf972. Configure here.
Summary
Math.random(),crypto.randomUUID(),crypto.randomBytes(),nanoid, anduuidusages with shared@sim/utils/randomand@sim/utils/idhelpers across 72 files@sim/utilsexports:deepClone,omit,filterUndefined(object),truncate(string),backoffWithJitter,parseRetryAfter(retry),getErrorMessage(errors)getErrorMessage, inlinesleep,JSON.parse(JSON.stringify(...))callsites across 500+ files to use shared utilitiesnoRestrictedImportsrule to ban directnanoid,uuid,crypto.randomUUID,crypto.randomBytesimports at lint timescripts/check-utils-enforcement.tsto catchMath.random()andcrypto.*global property access (which import analysis cannot catch), plus inline sleep/deepClone patternscheck:utilsscript topackage.jsonType of Change
Testing
Tested manually —
bun run check:utilspasses clean with 0 violationsChecklist