Skip to content

refactor: dedup and drop redundant existence checks#18

Merged
heznpc merged 1 commit intomainfrom
chore/simplify-findings
Apr 23, 2026
Merged

refactor: dedup and drop redundant existence checks#18
heznpc merged 1 commit intomainfrom
chore/simplify-findings

Conversation

@heznpc
Copy link
Copy Markdown
Member

@heznpc heznpc commented Apr 23, 2026

Post-/simplify review cleanup.

Findings addressed

Reuse (HIGH):

  • Extract formatScaffoldReport → reused by MCP handler + CLI (two 10-line duplicate output blocks → one)
  • Import SAFE_NAME in index.ts from scaffold.ts (was inline regex duplicate)

Efficiency (MEDIUM):

  • Drop existsSync(finalDest) before readdirSync(finalDest) — wrap readdirSync in try/catch for ENOENT (single syscall path)
  • Drop existsSync(finalDest) before rm(finalDest, { force: true })force: true handles absence
  • Drop existsSync(path) in updatePyproject — existing try/catch already handles ENOENT

Findings declined (noted as not worth fixing)

  • Inline format() helper in log.ts — Reviewer flagged as "unnecessary for single caller". Actually has 4 callers (debug/info/warn/error), so inlining would be anti-DRY. Skipped.
  • Stringly-typed CLI flag namesparseArgs options object IS the single source of truth; extracting a FLAGS = {...} const would add indirection for no benefit with only 6 flags. Skipped.
  • ScaffoldOptions param "sprawl" — 8 fields all narrowly scoped; splitting required/optional would churn callers. Skipped.
  • sleep() vs AbortSignal.timeout() — saves 2 lines but makes retry backoff less explicit. Skipped.
  • walkFiles recursion vs readdirSync({ recursive: true }) — ~10-20% faster for deep trees, negligible for typical scaffolds. Skipped.
  • AbortSignal listener leak in test fakeFetch — test-only, bounded per run. Skipped.
  • readVersion reads pkg.json per call--version runs at most once. Skipped.

Test plan

  • npm run build passes
  • npm test passes (36/36)
  • CI green

…eview)

Findings from a cross-cutting reuse + quality + efficiency review:

- Extract `formatScaffoldReport(name, template, result)` into scaffold.ts
  and reuse it in both the MCP tool handler (src/index.ts) and the CLI
  (src/cli.ts). Two identical 10-line output blocks collapsed to one.

- Import `SAFE_NAME` from scaffold.ts in src/index.ts instead of
  redefining the same regex inline in the Zod schema. Single source of
  truth for project-name validation; no drift if the rule tightens.

- Drop three redundant `existsSync` guards:
  - Before `readdirSync(finalDest)` — wrap in try/catch for ENOENT so
    the readdirSync itself tells us whether the dir exists, removing
    a double syscall.
  - Before `rm(finalDest, { force: true })` — `force: true` already
    tolerates absence.
  - Before `readFileSync` in `updatePyproject` — the existing try/catch
    already handles ENOENT.

Build + 36/36 tests still pass.
@heznpc heznpc merged commit 1625a65 into main Apr 23, 2026
1 check passed
@heznpc heznpc deleted the chore/simplify-findings branch April 23, 2026 20:13
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.

1 participant