Skip to content

Commit fb12b30

Browse files
authored
chore: export doc checker (#6632)
1 parent 73a0065 commit fb12b30

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

_tools/check_docs.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type DocNodeWithJsDoc<T = DocNodeBase> = T & {
3232

3333
const TS_SNIPPET = /```ts[\s\S]*?```/g;
3434
const ASSERTION_IMPORT =
35-
/from "@std\/(assert(\/[a-z-]+)?|testing\/(mock|snapshot|types))"/g;
35+
/from "@std\/(assert(\/[a-z-]+)?|expect(\/[a-z-]+)?|testing\/(mock|snapshot|types))"/g;
3636
const NEWLINE = "\n";
3737
const diagnostics: DocumentError[] = [];
3838

@@ -156,7 +156,7 @@ function assertHasSnippets(
156156
if (!(delim?.includes("no-assert") || delim?.includes("ignore"))) {
157157
assert(
158158
snippet.match(ASSERTION_IMPORT) !== null,
159-
"Snippet must contain assertion from '@std/assert'",
159+
"Snippet must contain assertion from `@std/assert`, `@std/expect` or `@std/testing`",
160160
document,
161161
);
162162
}
@@ -170,6 +170,7 @@ function assertHasExampleTag(
170170
tag.kind === "example"
171171
) as JsDocTagDocRequired[];
172172
assert(exampleTags?.length > 0, "Symbol must have an @example tag", document);
173+
if (exampleTags === undefined) return;
173174
for (const tag of exampleTags) {
174175
assert(
175176
tag.doc !== undefined,
@@ -415,15 +416,15 @@ async function assertDocs(specifiers: string[]) {
415416
}
416417
}
417418

418-
async function checkDocs(specifiers: string[]) {
419-
const lintStatus = await new Deno.Command(Deno.execPath(), {
419+
export async function checkDocs(specifiers: string[]) {
420+
const { success, stderr } = await new Deno.Command(Deno.execPath(), {
420421
args: ["doc", "--lint", ...specifiers],
421422
stdin: "inherit",
422423
stdout: "inherit",
423-
stderr: "inherit",
424+
stderr: "piped",
424425
}).output();
425-
if (!lintStatus.success) {
426-
throw new Error(new TextDecoder().decode(lintStatus.stderr));
426+
if (!success) {
427+
throw new Error(new TextDecoder().decode(stderr));
427428
}
428429

429430
await assertDocs(specifiers);

0 commit comments

Comments
 (0)