Skip to content

Fix code smells: remove casts, typeof branching, and non-null assertions - #38

Merged
chtitux merged 3 commits into
mainfrom
claude/find-code-smells-KI7Wu
Mar 8, 2026
Merged

chtitux merged 3 commits into
mainfrom
claude/find-code-smells-KI7Wu

Conversation

@chtitux

@chtitux chtitux commented Mar 8, 2026

Copy link
Copy Markdown
Contributor
  • Replace as unknown as Crypto double cast in checksum.ts with direct
    webcrypto.subtle.digest() call, avoiding type bridge entirely
  • Extract isString() and isNodeEnvironment() type guards into
    shared utils/env.ts, replacing inline typeof checks in zip-loader
    and gtfs-rt-loader
  • Replace unknown[] with proper ProtobufTimeRange[] and
    ProtobufEntitySelector[] types in gtfs-rt-loader interfaces
  • Refactor convertKeysToSnakeCase to use Object.entries() instead
    of for..in with as Record<string, unknown> cast
  • Replace as Record<string, unknown> widening casts on
    stmt.getAsObject() across all 11 query files with proper
    ParamsObject type from sql.js
  • Replace Map.get()! non-null assertions with optional chaining
    (?.) in rt-trip-updates.ts and stop-times.ts
  • Replace this.SQL!.Database() non-null assertion with explicit
    guard in gtfs-sqljs.ts

https://claude.ai/code/session_01A5mkjjjYzJ6Dib9jX167fR

claude added 3 commits March 8, 2026 04:59
- Replace `as unknown as Crypto` double cast in checksum.ts with direct
  `webcrypto.subtle.digest()` call, avoiding type bridge entirely
- Extract `isString()` and `isNodeEnvironment()` type guards into
  shared utils/env.ts, replacing inline `typeof` checks in zip-loader
  and gtfs-rt-loader
- Replace `unknown[]` with proper `ProtobufTimeRange[]` and
  `ProtobufEntitySelector[]` types in gtfs-rt-loader interfaces
- Refactor `convertKeysToSnakeCase` to use `Object.entries()` instead
  of `for..in` with `as Record<string, unknown>` cast
- Replace `as Record<string, unknown>` widening casts on
  `stmt.getAsObject()` across all 11 query files with proper
  `ParamsObject` type from sql.js
- Replace `Map.get()!` non-null assertions with optional chaining
  (`?.`) in rt-trip-updates.ts and stop-times.ts
- Replace `this.SQL!.Database()` non-null assertion with explicit
  guard in gtfs-sqljs.ts

https://claude.ai/code/session_01A5mkjjjYzJ6Dib9jX167fR
- Remove unused `string` from `loadGTFSZip()` parameter type; the only
  caller always passes binary data (string→binary conversion happens
  upstream in `fetchZip`)
- Remove unused `isString` helper from utils/env.ts
- Update CHANGELOG.md with all code smell fixes from this branch

https://claude.ai/code/session_01A5mkjjjYzJ6Dib9jX167fR
@chtitux
chtitux merged commit 2903113 into main Mar 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants