Readability: sync/async cleanup, DRY, type safety, config fixes#55
Readability: sync/async cleanup, DRY, type safety, config fixes#55KyleAMathews merged 12 commits intoTanStack:mainfrom
Conversation
…d no error, and make the config type safe
… for compilation (therefore no need for declaration)
c4690a4 to
bdcb763
Compare
commit: |
Resolve conflicts preserving origin/main's new features (help system, workspace scanning, keyword detection, display module) while keeping the PR's sync/async cleanup for scanForIntents and scanLibrary. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Revert unrelated eslint.config.js changes (array-type, import/order) - Remove remaining async/await from 9 scanner tests - Use mockFetchNotOk() and requireFirstSkill() in staleness test - Remove redundant non-null assertions in skills test - Remove unnecessary await in scanIntentsOrFail Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 3c1dae7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughConverts Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/intent/tests/staleness.test.ts (1)
49-54: Minor: Redundant assertion before throw.The
expect(skill).toBeDefined()on line 51 will already fail the test ifskillis undefined. The subsequentif (!skill) throwon line 52 is only needed for TypeScript narrowing. Consider simplifying:♻️ Suggested simplification
function requireFirstSkill(report: Awaited<ReturnType<typeof checkStaleness>>) { const skill = report.skills[0] - expect(skill).toBeDefined() if (!skill) throw new Error('Expected at least one skill in staleness report') return skill }The throw provides both the type narrowing and a clear error message, making the
expectredundant.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/intent/tests/staleness.test.ts` around lines 49 - 54, In function requireFirstSkill, remove the redundant test assertion expect(skill).toBeDefined() and keep the existing runtime null-check and throw (if (!skill) throw new Error(...)) to provide TypeScript narrowing and the clear error message; this simplifies the function while preserving type-safety and test clarity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/intent/tests/staleness.test.ts`:
- Around line 49-54: In function requireFirstSkill, remove the redundant test
assertion expect(skill).toBeDefined() and keep the existing runtime null-check
and throw (if (!skill) throw new Error(...)) to provide TypeScript narrowing and
the clear error message; this simplifies the function while preserving
type-safety and test clarity.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b4dd4deb-8abf-42a8-95bd-d6f2d61d91dd
📒 Files selected for processing (10)
.changeset/neat-pots-melt.mdpackages/intent/src/cli.tspackages/intent/src/intent-library.tspackages/intent/src/library-scanner.tspackages/intent/src/scanner.tspackages/intent/tests/library-scanner.test.tspackages/intent/tests/scanner.test.tspackages/intent/tests/skills.test.tspackages/intent/tests/staleness.test.tspackages/intent/tsconfig.json
|
Thank you very much! |
|
OMG Tanner himself approved it |
Summary
Makes
scanForIntentsandscanLibrarysynchronous — both functions only usereadFileSync/existsSync/readdirSyncinternally, so theasync/Promisewrapper was misleading. Also cleans up test DRY and type safety.Approach
Sync/async correction
asynckeyword andPromise<>return type fromscanForIntents()andscanLibrary()await, switch test assertions from.rejects.toThrow()to.toThrow()scanIntentsOrFailin cli.ts stays async (it uses dynamicimport()) but drops the redundantawaiton the now-sync callDRY test helpers (
staleness.test.ts)mockFetchVersion(),mockFetchNotOk(),requireFirstSkill()— each replaces a 3-4 line repeated patternfindSkillFilesfromsrc/utils.tsinstead of reimplementing inskills.test.tsType safety (
skills.test.ts)!match[1] || match[2] === undefined) before accessing regex capture groups, respectingnoUncheckedIndexedAccess: trueConfig (
tsconfig.json)outDir/declaration/noEmit: falseoverrides —tsdownhandles the build, these were dead configKey invariants
scanForIntentsandscanLibrarymust remain purely synchronous (noawait, no.then(), no dynamicimport()inside them).toThrow(), not.rejects.toThrow()Non-goals
Verification
pnpm run build pnpm vitest run # 205 tests passFiles changed
src/scanner.tsasync→ sync forscanForIntentssrc/library-scanner.tsasync→ sync forscanLibrarysrc/intent-library.tsawaitfromcmdListand its call sitesrc/cli.tsawaitinscanIntentsOrFailtests/scanner.test.tsasync/awaitfrom all 26 teststests/library-scanner.test.tsasync/await, usescriptPathhelpertests/staleness.test.tstests/skills.test.tsfindSkillFiles, tighten type guardstsconfig.json.changeset/neat-pots-melt.md🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor
Tests