Skip to content

Commit 2bbb4db

Browse files
committed
ref(runtime): let CaptureAssessment carry the guarantee it already checks
`assessCaptureRule` confirms `candidate.id` is a string before returning `ok: true`, but the return type said `CaptureRule`, whose `id` is optional — so the caller had to cast it back with `as string`. The point of one shared assessor is that its guarantee can be trusted by both callers. A guarantee the type throws away is one the next reader has to re-derive, and a cast is what they reach for. `CaptureRule & { id: string }` states it instead, so reordering the checks such that `id` is no longer validated becomes a compile error rather than an `undefined` id at runtime. Found by the review on #216.
1 parent 3198d52 commit 2bbb4db

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎packages/cli/src/rules/runtime/discover.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function asMatchMode(value: unknown): MatchMode | undefined {
7979
* person reading `verify` output. Nothing branches on it.
8080
*/
8181
export type CaptureAssessment =
82-
| { ok: true; rule: CaptureRule; match: MatchMode }
82+
| { ok: true; rule: CaptureRule & { id: string }; match: MatchMode }
8383
| { ok: false; reason: string };
8484

8585
export function assessCaptureRule(value: unknown): CaptureAssessment {
@@ -140,7 +140,7 @@ export function assessCaptureRule(value: unknown): CaptureAssessment {
140140
`implement (valid: ${MATCH_MODES.join(", ")})`,
141141
};
142142
}
143-
return { ok: true, rule: candidate as CaptureRule, match };
143+
return { ok: true, rule: candidate as CaptureRule & { id: string }, match };
144144
}
145145

146146
/** Load and parse the capture rules of a single runtime-rule directory. */
@@ -175,7 +175,7 @@ async function loadCaptureRules(
175175
loaded.push({
176176
file,
177177
fileName,
178-
id: rule.id as string,
178+
id: rule.id,
179179
name: rule.metadata.taskless.name,
180180
language: rule.language,
181181
match,

0 commit comments

Comments
 (0)