Skip to content

Commit 1b4d811

Browse files
waleedlatif1claude
andcommitted
chore(utils): remove unused utilities (asserts, safeJsonParse, isNonNull)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4b89bd6 commit 1b4d811

5 files changed

Lines changed: 1 addition & 54 deletions

File tree

.claude/rules/global.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ Use shared helpers from `@/lib/core/utils/helpers` instead of writing inline imp
3636
- `sleep(ms)` — async delay. Never write `new Promise(resolve => setTimeout(resolve, ms))`
3737
- `toError(value)` — normalize unknown caught values to `Error`. Never write `e instanceof Error ? e : new Error(String(e))`
3838
- `toError(value).message` — get error message safely. Never write `e instanceof Error ? e.message : String(e)`
39-
- `safeJsonParse(str, fallback?)` — parse JSON without throwing. Never write `try { JSON.parse(str) } catch { return default }`
40-
- `isNonNull(value)` — type-narrowing filter predicate for null/undefined
41-
42-
Use assertion utilities from `@/lib/core/utils/asserts`:
43-
44-
- `invariant(condition, message)` — assert a condition is truthy, throws if not
45-
- `assertNever(value)` — exhaustive switch/if-else check, TypeScript errors at compile time if a case is unhandled
4639

4740
```typescript
4841
// ✗ Bad

.cursor/rules/global.mdc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ Use shared helpers from `@/lib/core/utils/helpers` instead of writing inline imp
4343
- `sleep(ms)` — async delay. Never write `new Promise(resolve => setTimeout(resolve, ms))`
4444
- `toError(value)` — normalize unknown caught values to `Error`. Never write `e instanceof Error ? e : new Error(String(e))`
4545
- `toError(value).message` — get error message safely. Never write `e instanceof Error ? e.message : String(e)`
46-
- `safeJsonParse(str, fallback?)` — parse JSON without throwing. Never write `try { JSON.parse(str) } catch { return default }`
47-
- `isNonNull(value)` — type-narrowing filter predicate for null/undefined
48-
49-
Use assertion utilities from `@/lib/core/utils/asserts`:
50-
51-
- `invariant(condition, message)` — assert a condition is truthy, throws if not
52-
- `assertNever(value)` — exhaustive switch/if-else check, TypeScript errors at compile time if a case is unhandled
5346

5447
```typescript
5548
// ✗ Bad

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ You are a professional software engineer. All code must follow best practices: a
88
- **Comments**: Use TSDoc for documentation. No `====` separators. No non-TSDoc comments
99
- **Styling**: Never update global styles. Keep all styling local to components
1010
- **ID Generation**: Never use `crypto.randomUUID()`, `nanoid`, or `uuid` package. Use `generateId()` (UUID v4) or `generateShortId()` (compact) from `@/lib/core/utils/uuid`
11-
- **Common Utilities**: Use shared helpers from `@/lib/core/utils/helpers` instead of inline implementations. `sleep(ms)` for delays, `toError(e)` to normalize caught values, `safeJsonParse(str, fallback?)` for safe JSON parsing, `isNonNull(v)` for type-narrowing null filters. Use `invariant(cond, msg)` and `assertNever(val)` from `@/lib/core/utils/asserts` for runtime assertions and exhaustive checks.
11+
- **Common Utilities**: Use shared helpers from `@/lib/core/utils/helpers` instead of inline implementations. `sleep(ms)` for delays, `toError(e)` to normalize caught values.
1212
- **Package Manager**: Use `bun` and `bunx`, not `npm` and `npx`
1313

1414
## Architecture

apps/sim/lib/core/utils/asserts.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

apps/sim/lib/core/utils/helpers.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,6 @@ export function sleep(ms: number): Promise<void> {
66
return new Promise((resolve) => setTimeout(resolve, ms))
77
}
88

9-
/**
10-
* Parses a JSON string, returning a fallback value on failure instead of throwing.
11-
* Replaces the common `try { JSON.parse(str) } catch { return default }` pattern.
12-
*/
13-
export function safeJsonParse<T>(value: string): T | undefined
14-
export function safeJsonParse<T>(value: string, fallback: T): T
15-
export function safeJsonParse<T>(value: string, fallback?: T): T | undefined {
16-
try {
17-
return JSON.parse(value) as T
18-
} catch {
19-
return fallback
20-
}
21-
}
22-
23-
/**
24-
* Type-safe filter predicate that removes null and undefined values.
25-
* Fixes the common `.filter(Boolean)` pattern which doesn't narrow types in TypeScript.
26-
*/
27-
export function isNonNull<T>(value: T | null | undefined): value is T {
28-
return value != null
29-
}
30-
319
/**
3210
* Normalizes an unknown caught value into an Error instance.
3311
* Replaces the common `e instanceof Error ? e : new Error(String(e))` pattern in catch clauses.

0 commit comments

Comments
 (0)