Skip to content

Commit 23e4962

Browse files
KyleAMathewsclaude
andcommitted
Apply code review fixes and simplifications
- Fix: Unknown CLI commands now exit with code 1 instead of 0 - Fix: Catch block only handles ENOENT, re-throws other errors - Fix: Add scripts field to package.json for monorepo consistency - Refactor: Use early return pattern in listSkills for clarity - Refactor: Replace nested ternary with helper function in docs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 376593a commit 23e4962

3 files changed

Lines changed: 38 additions & 24 deletions

File tree

‎packages/skills/bin/cli.js‎

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,28 @@ function listSkills(dir, prefix = '') {
1414
const itemPath = join(dir, item)
1515
const stat = statSync(itemPath)
1616

17-
if (stat.isDirectory()) {
18-
const skillPath = join(itemPath, 'SKILL.md')
19-
try {
20-
const content = readFileSync(skillPath, 'utf-8')
21-
const nameMatch = content.match(/^name:\s*(.+)$/m)
22-
const descMatch = content.match(/description:\s*\|?\s*\n?\s*(.+)/m)
23-
24-
const name = nameMatch?.[1] || item
25-
const desc = descMatch?.[1]?.trim() || 'No description'
26-
27-
console.log(`${prefix}${name}`)
28-
console.log(`${prefix} ${desc}`)
29-
console.log()
30-
} catch {
31-
// No SKILL.md, check subdirectories
17+
if (!stat.isDirectory()) continue
18+
19+
const skillPath = join(itemPath, 'SKILL.md')
20+
try {
21+
const content = readFileSync(skillPath, 'utf-8')
22+
const nameMatch = content.match(/^name:\s*(.+)$/m)
23+
const descMatch = content.match(/description:\s*\|?\s*\n?\s*(.+)/m)
24+
25+
const name = nameMatch?.[1] || item
26+
const desc = descMatch?.[1]?.trim() || 'No description'
27+
28+
console.log(`${prefix}${name}`)
29+
console.log(`${prefix} ${desc}`)
30+
console.log()
31+
} catch (err) {
32+
if (err.code !== 'ENOENT') {
33+
throw err
3234
}
33-
34-
// Recurse into subdirectories
35-
listSkills(itemPath, prefix + ' ')
35+
// No SKILL.md, check subdirectories
3636
}
37+
38+
listSkills(itemPath, prefix + ' ')
3739
}
3840
}
3941

@@ -89,7 +91,7 @@ switch (command) {
8991
case 'help':
9092
case '--help':
9193
case '-h':
92-
default:
94+
case undefined:
9395
console.log(`TanStack DB Skills CLI
9496
9597
Usage:
@@ -104,4 +106,9 @@ Examples:
104106
db-skills show tanstack-db/mutations
105107
`)
106108
break
109+
110+
default:
111+
console.error(`Unknown command: ${command}`)
112+
console.log(`Run 'db-skills help' for usage information.`)
113+
process.exit(1)
107114
}

‎packages/skills/package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@
3131
],
3232
"engines": {
3333
"node": ">=18"
34+
},
35+
"scripts": {
36+
"lint": "true"
3437
}
3538
}

‎packages/skills/skills/tanstack-db/live-queries/references/functional-variants.md‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ const { data } = useLiveQuery((q) =>
2525
id: row.user.id,
2626
displayName: `${row.user.firstName} ${row.user.lastName}`.trim(),
2727
emailDomain: row.user.email.split('@')[1],
28-
ageGroup:
29-
row.user.age < 25 ? 'young' : row.user.age < 50 ? 'adult' : 'senior',
28+
ageGroup: getAgeGroup(row.user.age),
3029
isHighEarner: row.user.salary > 75000,
3130
})),
3231
)
32+
33+
function getAgeGroup(age: number): 'young' | 'adult' | 'senior' {
34+
if (age < 25) return 'young'
35+
if (age < 50) return 'adult'
36+
return 'senior'
37+
}
3338
```
3439

3540
## fn.where
@@ -90,7 +95,7 @@ const { data } = useLiveQuery((q) =>
9095
},
9196
demographics: {
9297
age: user.age,
93-
ageGroup: user.age < 25 ? 'young' : user.age < 50 ? 'adult' : 'senior',
98+
ageGroup: getAgeGroup(user.age),
9499
isAdult: user.age >= 18,
95100
},
96101
profileStrength: calculateProfileStrength(user),
@@ -145,8 +150,7 @@ const { data } = useLiveQuery((q) =>
145150
(row): ProcessedUser => ({
146151
id: row.user.id,
147152
name: row.user.name,
148-
ageGroup:
149-
row.user.age < 25 ? 'young' : row.user.age < 50 ? 'adult' : 'senior',
153+
ageGroup: getAgeGroup(row.user.age),
150154
}),
151155
),
152156
)

0 commit comments

Comments
 (0)