@@ -369,7 +369,7 @@ async function getPackageInfosEtc(
369369 return { pkgInfo : result , popularityLevel : downloadsToPopularityLevel ( maxDownloads ) } ;
370370}
371371
372- async function categorizeFile ( path : string , contents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
372+ async function categorizeFile ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
373373 // https://regex101.com/r/eFvtrz/1
374374 const match = / ^ t y p e s \/ ( .* ?) \/ .* ?[ ^ \/ ] (?: \. ( d \. t s | t s x ? | m d ) ) ? $ / . exec ( path ) ;
375375 if ( ! match ) return [ null , { path, kind : "infrastructure" } ] ;
@@ -379,26 +379,26 @@ async function categorizeFile(path: string, contents: (ref: string) => Promise<s
379379 case "ts" : case "tsx" : return [ pkg , { path, kind : "test" } ] ;
380380 case "md" : return [ pkg , { path, kind : "markdown" } ] ;
381381 default :
382- const suspect = await configSuspicious ( path , contents ) ;
382+ const suspect = await configSuspicious ( path , getContents ) ;
383383 return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , ...suspect } ] ;
384384 }
385385}
386386
387387interface ConfigSuspicious {
388388 ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
389- [ basename : string ] : ( text : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
389+ [ basename : string ] : ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
390390} ;
391391const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
392392 const basename = path . replace ( / .* \/ / , "" ) ;
393- if ( ! ( basename in configSuspicious ) ) return { suspect : `edited` } ;
394- const text = await getContents ( "head" ) ;
395- if ( text === undefined ) return { suspect : `couldn't fetch contents` } ;
396393 const tester = configSuspicious [ basename ] ;
397- return tester ( text , getContents ) ;
394+ if ( ! tester ) return { suspect : `edited` } ;
395+ const newText = await getContents ( "head" ) ;
396+ if ( newText === undefined ) return { suspect : `couldn't fetch contents` } ;
397+ return tester ( newText , getContents ) ;
398398} ) ;
399- configSuspicious [ "OTHER_FILES.txt" ] = async contents =>
399+ configSuspicious [ "OTHER_FILES.txt" ] = async newText =>
400400 // not empty
401- ( contents . length === 0 ) ? { suspect : "empty" }
401+ ( newText . length === 0 ) ? { suspect : "empty" }
402402 : undefined ;
403403configSuspicious [ "package.json" ] = makeJsonCheckerFromCore (
404404 { private : true } ,
@@ -429,9 +429,9 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
429429// to it, ignoring some keys (JSON Patch paths). The ignored properties are in most cases checked
430430// elsewhere (dtslint), and in some cases they are irrelevant.
431431function makeJsonCheckerFromCore ( requiredForm : any , ignoredKeys : string [ ] ) {
432- return async ( contents : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
432+ return async ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
433433 let suggestion : any ;
434- try { suggestion = JSON . parse ( contents ) ; } catch ( e ) { return { suspect : "couldn't parse json" } ; }
434+ try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { return { suspect : "couldn't parse json" } ; }
435435 const newJson = jsonDiff . deepClone ( suggestion ) ;
436436 jsonDiff . applyPatch ( newJson , ignoredKeys . map ( path => ( { op : "remove" , path } ) ) ) ;
437437 const towardsIt = jsonDiff . deepClone ( requiredForm ) ;
@@ -474,7 +474,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[]) {
474474 ? prettier . format ( JSON . stringify ( suggestion ) , { tabWidth : 4 , filepath : ".json" } )
475475 : JSON . stringify ( suggestion , undefined , 4 ) + "\n"
476476 ) . split ( / ^ / m) ;
477- const lines = contents . split ( / ^ / m) ;
477+ const lines = newText . split ( / ^ / m) ;
478478 // When suggestionLines is empty, that suggests removing all
479479 // of the different lines
480480 let startLine = 1 ;
0 commit comments