@@ -43,7 +43,17 @@ const validExtensions = ['js', 'tsx'];
4343 * @param opts.extension extension to treat the example as if it does not specify one
4444 * @param opts.writeBack whether to update examples with mutations made by the linter
4545 */
46- async function lintExamples ( { command, args, extension, writeBack} ) {
46+ async function lintExamples ( {
47+ command,
48+ args,
49+ extension,
50+ writeBack,
51+ } : {
52+ command : string ;
53+ args ?: string [ ] ;
54+ extension : string ;
55+ writeBack : boolean ;
56+ } ) {
4757 if ( ! validExtensions . includes ( extension ) ) {
4858 console . error (
4959 `Invalid extension "${ extension } " (should be one of ${ JSON . stringify (
@@ -73,12 +83,17 @@ async function lintExamples({command, args, extension, writeBack}) {
7383 *
7484 * @param extension extension to treat the example as if it does not specify
7585 */
76- async function extractExamples ( extension ) {
86+ async function extractExamples ( extension : string ) {
7787 const documents = await glob . glob ( '**/*.md' , {
7888 cwd : documentsRoot ,
7989 absolute : true ,
8090 } ) ;
81- const mappings = [ ] ;
91+ const mappings : {
92+ documentPath : string ;
93+ examplePath : string ;
94+ offset : number ;
95+ length : number ;
96+ } [ ] = [ ] ;
8297
8398 await fs . mkdir ( outputRoot , { recursive : true } ) ;
8499 await fs . rm ( outputRoot , { recursive : true } ) ;
@@ -99,7 +114,10 @@ async function extractExamples(extension) {
99114 * @param filename absolute filename of the documents root
100115 * @param extension extension to treat the example as if it does not specify
101116 */
102- async function extractExamplesFromDocument ( filename , extension ) {
117+ async function extractExamplesFromDocument (
118+ filename : string ,
119+ extension : string ,
120+ ) {
103121 const fileContents = await fs . readFile ( filename , {
104122 encoding : 'utf-8' ,
105123 } ) ;
@@ -167,7 +185,7 @@ async function extractExamplesFromDocument(filename, extension) {
167185 * @param command an npx command to run as the linter tool
168186 * @param args extra arguments to be passed to the linter
169187 */
170- async function runLinter ( command , args ) {
188+ async function runLinter ( command : string , args : string [ ] ) {
171189 const combinedArgs = [ ...processArgs , ...args ] ;
172190
173191 try {
@@ -178,6 +196,7 @@ async function runLinter(command, args) {
178196
179197 return 0 ;
180198 } catch ( ex ) {
199+ // @ts -expect-error
181200 return ex . status ;
182201 }
183202}
@@ -187,8 +206,23 @@ async function runLinter(command, args) {
187206 *
188207 * @param mappings file mappings generated by extractExamples()
189208 */
190- async function updateDocuments ( mappings ) {
191- const mappingsByDocument = { } ;
209+ async function updateDocuments (
210+ mappings : {
211+ documentPath : string ;
212+ examplePath : string ;
213+ offset : number ;
214+ length : number ;
215+ } [ ] ,
216+ ) {
217+ const mappingsByDocument : Record <
218+ string ,
219+ {
220+ documentPath : string ;
221+ examplePath : string ;
222+ offset : number ;
223+ length : number ;
224+ } [ ]
225+ > = { } ;
192226 for ( const mapping of mappings ) {
193227 if ( mappingsByDocument [ mapping . documentPath ] === undefined ) {
194228 mappingsByDocument [ mapping . documentPath ] = [ ] ;
0 commit comments