11#!/usr/bin/env tsx
22import { readFileSync , writeFileSync } from 'node:fs' ;
3- // Import index.ts first to populate the test data
3+ // Import index.ts to populate the test data via side effect
4+ // eslint-disable-next-line import/no-unassigned-import, n/file-extension-in-import
45import './index.ts' ;
6+ // eslint-disable-next-line n/file-extension-in-import
57import { getTests } from './collector.ts' ;
68
79// Read the generated .d.ts file
@@ -12,33 +14,32 @@ const dtsContent = readFileSync(dtsPath, 'utf8');
1214const lines = dtsContent . split ( '\n' ) ;
1315const outputLines : string [ ] = [ ] ;
1416
15- for ( let i = 0 ; i < lines . length ; i ++ ) {
16- const line = lines [ i ] ;
17-
17+ for ( const line of lines ) {
1818 // Check if this is a function declaration
19- const match = line . match ( / ^ e x p o r t d e c l a r e c o n s t ( \w + ) : / ) ;
19+ const match = / ^ e x p o r t d e c l a r e c o n s t ( \w + ) : / . exec ( line ) ;
2020 if ( match ) {
2121 const functionName = match [ 1 ] ;
22-
22+
2323 // Get the tests/examples for this function
2424 const examples = getTests ( functionName ) ;
25-
25+
2626 // Only add examples if they exist and aren't just references to other functions
2727 if ( examples && examples . length > 0 && examples [ 0 ] !== 'combinedTestOnly' ) {
2828 // Filter to only include actual URLs (not references to other functions)
29- const urlExamples = examples . filter ( url => url . startsWith ( 'http' ) ) ;
30-
29+ const urlExamples = examples . filter ( ( url : string ) => url . startsWith ( 'http' ) ) ;
30+
3131 if ( urlExamples . length > 0 ) {
3232 // Add JSDoc comment with examples before the declaration
3333 outputLines . push ( '/**' ) ;
3434 for ( const url of urlExamples ) {
3535 outputLines . push ( ` * @example ${ url } ` ) ;
3636 }
37+
3738 outputLines . push ( ' */' ) ;
3839 }
3940 }
4041 }
41-
42+
4243 outputLines . push ( line ) ;
4344}
4445
0 commit comments