@@ -23,132 +23,48 @@ import {
2323 type Location ,
2424 type TsTypeDef ,
2525} from "@deno/doc" ;
26- import { pooledMap } from "@std/async/pool" ;
26+ import { walk } from "@std/fs/walk" ;
27+ import { join } from "@std/path/join" ;
28+ import { distinctBy } from "@std/collections/distinct-by" ;
29+ import { toFileUrl } from "@std/path/to-file-url" ;
2730
2831type DocNodeWithJsDoc < T = DocNodeBase > = T & {
2932 jsDoc : JsDoc ;
3033} ;
3134
32- const ENTRY_POINTS = [
33- "../assert/mod.ts" ,
34- "../assert/unstable_never.ts" ,
35- "../async/mod.ts" ,
36- "../bytes/mod.ts" ,
37- "../cache/mod.ts" ,
38- "../cbor/mod.ts" ,
39- "../cli/mod.ts" ,
40- "../cli/unstable_spinner.ts" ,
41- "../cli/unstable_prompt_multiple_select.ts" ,
42- "../crypto/mod.ts" ,
43- "../collections/mod.ts" ,
44- "../csv/mod.ts" ,
45- "../csv/unstable_stringify.ts" ,
46- "../data_structures/mod.ts" ,
47- "../data_structures/unstable_bidirectional_map.ts" ,
48- "../datetime/mod.ts" ,
49- "../dotenv/mod.ts" ,
50- "../encoding/mod.ts" ,
51- "../encoding/unstable_hex.ts" ,
52- "../encoding/unstable_base32.ts" ,
53- "../encoding/unstable_base64.ts" ,
54- "../encoding/unstable_hex.ts" ,
55- "../encoding/unstable_base64_stream.ts" ,
56- "../encoding/unstable_base32_stream.ts" ,
57- "../encoding/unstable_hex_stream.ts" ,
58- "../expect/mod.ts" ,
59- "../fmt/bytes.ts" ,
60- "../fmt/colors.ts" ,
61- "../fmt/duration.ts" ,
62- "../fmt/printf.ts" ,
63- "../front_matter/mod.ts" ,
64- "../front_matter/unstable_yaml.ts" ,
65- "../fs/mod.ts" ,
66- "../fs/unstable_chmod.ts" ,
67- "../fs/unstable_copy_file.ts" ,
68- "../fs/unstable_link.ts" ,
69- "../fs/unstable_lstat.ts" ,
70- "../fs/unstable_make_temp_dir.ts" ,
71- "../fs/unstable_make_temp_file.ts" ,
72- "../fs/unstable_mkdir.ts" ,
73- "../fs/unstable_read_dir.ts" ,
74- "../fs/unstable_read_file.ts" ,
75- "../fs/unstable_read_link.ts" ,
76- "../fs/unstable_read_text_file.ts" ,
77- "../fs/unstable_real_path.ts" ,
78- "../fs/unstable_remove.ts" ,
79- "../fs/unstable_rename.ts" ,
80- "../fs/unstable_stat.ts" ,
81- "../fs/unstable_symlink.ts" ,
82- "../fs/unstable_truncate.ts" ,
83- "../fs/unstable_types.ts" ,
84- "../fs/unstable_umask.ts" ,
85- "../fs/unstable_utime.ts" ,
86- "../fs/unstable_write_file.ts" ,
87- "../fs/unstable_write_text_file.ts" ,
88- "../html/mod.ts" ,
89- "../html/unstable_is_valid_custom_element_name.ts" ,
90- "../http/mod.ts" ,
91- "../http/unstable_header.ts" ,
92- "../http/unstable_method.ts" ,
93- "../http/unstable_signed_cookie.ts" ,
94- "../ini/mod.ts" ,
95- "../internal/mod.ts" ,
96- "../io/mod.ts" ,
97- "../json/mod.ts" ,
98- "../jsonc/mod.ts" ,
99- "../log/base_handler.ts" ,
100- "../log/file_handler.ts" ,
101- "../log/warn.ts" ,
102- "../log/critical.ts" ,
103- "../log/debug.ts" ,
104- "../log/error.ts" ,
105- "../log/info.ts" ,
106- "../log/console_handler.ts" ,
107- "../log/formatters.ts" ,
108- "../log/get_logger.ts" ,
109- "../log/logger.ts" ,
110- "../media_types/mod.ts" ,
111- "../msgpack/mod.ts" ,
112- "../net/mod.ts" ,
113- "../net/unstable_get_network_address.ts" ,
114- "../path/mod.ts" ,
115- "../path/unstable_basename.ts" ,
116- "../path/unstable_dirname.ts" ,
117- "../path/unstable_extname.ts" ,
118- "../path/unstable_join.ts" ,
119- "../path/unstable_normalize.ts" ,
120- "../path/posix/mod.ts" ,
121- "../path/windows/mod.ts" ,
122- "../random/mod.ts" ,
123- "../regexp/mod.ts" ,
124- "../semver/mod.ts" ,
125- "../streams/mod.ts" ,
126- "../streams/unstable_fixed_chunk_stream.ts" ,
127- "../streams/unstable_to_lines.ts" ,
128- "../streams/unstable_to_bytes.ts" ,
129- "../tar/mod.ts" ,
130- "../text/mod.ts" ,
131- "../text/unstable_slugify.ts" ,
132- "../text/unstable_to_constant_case.ts" ,
133- "../testing/bdd.ts" ,
134- "../testing/mock.ts" ,
135- "../testing/snapshot.ts" ,
136- "../testing/time.ts" ,
137- "../testing/types.ts" ,
138- "../toml/mod.ts" ,
139- "../ulid/mod.ts" ,
140- "../uuid/mod.ts" ,
141- "../uuid/unstable_v7.ts" ,
142- "../webgpu/mod.ts" ,
143- "../yaml/mod.ts" ,
144- ] as const ;
35+ const ROOT = new URL ( "../" , import . meta. url ) ;
36+ const ENTRY_POINT_URLS = [ ] ;
37+ for await (
38+ const { path } of walk ( ROOT , { exts : [ ".json" ] , match : [ / d e n o .j s o n $ / ] } )
39+ ) {
40+ const { exports } = await Deno . readTextFile ( path ) . then ( JSON . parse ) ;
41+
42+ if ( ! exports ) continue ;
43+ for ( const relativeFilePath of Object . values < string > ( exports ) ) {
44+ if ( ! relativeFilePath . endsWith ( ".ts" ) ) continue ;
45+
46+ const filePath = join ( path , ".." , relativeFilePath ) ;
47+
48+ // Ignores 4 files in @std/log package
49+ if (
50+ / l o g [ / \\ ] ( m o d | l e v e l s | s e t u p | r o t a t i n g _ f i l e _ h a n d l e r ) \. t s $ / . test ( filePath )
51+ ) {
52+ // deno-lint-ignore no-console
53+ console . warn (
54+ `Doc check for ${ filePath } is ignored. Visit https://github.com/denoland/std/issues/6124 for more details.` ,
55+ ) ;
56+ continue ;
57+ }
58+
59+ ENTRY_POINT_URLS . push ( toFileUrl ( filePath ) . href ) ;
60+ }
61+ }
14562
14663const TS_SNIPPET = / ` ` ` t s [ \s \S ] * ?` ` ` / g;
14764const ASSERTION_IMPORT =
14865 / f r o m " @ s t d \/ ( a s s e r t ( \/ [ a - z - ] + ) ? | t e s t i n g \/ ( m o c k | s n a p s h o t | t y p e s ) ) " / g;
14966const NEWLINE = "\n" ;
15067const diagnostics : DocumentError [ ] = [ ] ;
151- const snippetPromises : ( ( ) => Promise < void > ) [ ] = [ ] ;
15268
15369class DocumentError extends Error {
15470 constructor (
@@ -274,10 +190,8 @@ function assertSnippetsWork(
274190 document ,
275191 ) ,
276192 ) ;
277- return ;
278- } else {
279- return ;
280193 }
194+ return ;
281195 }
282196 for ( let snippet of snippets ) {
283197 const delim = snippet . split ( NEWLINE ) [ 0 ] ;
@@ -413,7 +327,9 @@ function assertClassDocs(document: DocNodeWithJsDoc<DocNodeClass>) {
413327 for ( const typeParam of document . classDef . typeParams ) {
414328 assertHasTypeParamTags ( document , typeParam . name ) ;
415329 }
416- assertHasExampleTag ( document ) ;
330+ if ( ! document . jsDoc . tags ?. some ( ( tag ) => tag . kind === "example" ) ) {
331+ assertHasExampleTag ( document ) ;
332+ }
417333
418334 for ( const property of document . classDef . properties ) {
419335 if ( property . jsDoc === undefined ) continue ; // this is caught by `deno doc --lint`
@@ -547,10 +463,13 @@ async function checkDocs(specifier: string) {
547463 const docs = ( await doc ( [ specifier ] , { resolve } ) ) [ specifier ] ! ;
548464 for ( const d of docs . filter ( isExported ) ) {
549465 if ( d . jsDoc === undefined ) continue ; // this is caught by other checks
466+
550467 const document = d as DocNodeWithJsDoc < DocNode > ;
551468 switch ( document . kind ) {
552469 case "moduleDoc" : {
553- assertModuleDoc ( document ) ;
470+ if ( document . location . filename . endsWith ( "/mod.ts" ) ) {
471+ assertModuleDoc ( document ) ;
472+ }
554473 break ;
555474 }
556475 case "function" : {
@@ -567,10 +486,6 @@ async function checkDocs(specifier: string) {
567486 }
568487}
569488
570- const ENTRY_POINT_URLS = ENTRY_POINTS . map ( ( entry ) =>
571- new URL ( entry , import . meta. url ) . href
572- ) ;
573-
574489const lintStatus = await new Deno . Command ( Deno . execPath ( ) , {
575490 args : [ "doc" , "--lint" , ...ENTRY_POINT_URLS ] ,
576491 stdin : "inherit" ,
@@ -587,18 +502,13 @@ if (!lintStatus.success) {
587502 Deno . exit ( 1 ) ;
588503}
589504
590- await Promise . all ( ENTRY_POINT_URLS . map ( checkDocs ) ) ;
591-
592- const iter = pooledMap (
593- navigator . hardwareConcurrency ,
594- snippetPromises ,
595- ( fn ) => fn ( ) ,
596- ) ;
597- for await ( const _ of iter ) {
598- // noop
505+ for ( const url of ENTRY_POINT_URLS ) {
506+ await checkDocs ( url ) ;
599507}
508+
600509if ( diagnostics . length > 0 ) {
601- for ( const error of diagnostics ) {
510+ const errors = distinctBy ( diagnostics , ( e ) => e . message + e . cause ) ;
511+ for ( const error of errors ) {
602512 // deno-lint-ignore no-console
603513 console . error (
604514 `%c[error] %c${ error . message } %cat ${ error . cause } ` ,
@@ -609,6 +519,6 @@ if (diagnostics.length > 0) {
609519 }
610520
611521 // deno-lint-ignore no-console
612- console . log ( `%c${ diagnostics . length } errors found` , "color: red" ) ;
522+ console . log ( `%c${ errors . length } errors found` , "color: red" ) ;
613523 Deno . exit ( 1 ) ;
614524}
0 commit comments