@@ -333,7 +333,7 @@ async function getPackageInfosEtc(
333
333
return { pkgInfo : result , popularityLevel : downloadsToPopularityLevel ( maxDownloads ) } ;
334
334
}
335
335
336
- async function categorizeFile ( path : string , contents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
336
+ async function categorizeFile ( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < [ string | null , FileInfo ] > {
337
337
// https://regex101.com/r/eFvtrz/1
338
338
const match = / ^ t y p e s \/ ( .* ?) \/ .* ?[ ^ \/ ] (?: \. ( d \. t s | t s x ? | m d ) ) ? $ / . exec ( path ) ;
339
339
if ( ! match ) return [ null , { path, kind : "infrastructure" } ] ;
@@ -344,26 +344,26 @@ async function categorizeFile(path: string, contents: (ref: string) => Promise<s
344
344
case "ts" : case "tsx" : return [ pkg , { path, kind : "test" } ] ;
345
345
case "md" : return [ pkg , { path, kind : "markdown" } ] ;
346
346
default : {
347
- const suspect = await configSuspicious ( path , contents ) ;
347
+ const suspect = await configSuspicious ( path , getContents ) ;
348
348
return [ pkg , { path, kind : suspect ? "package-meta" : "package-meta-ok" , ...suspect } ] ;
349
349
}
350
350
}
351
351
}
352
352
353
353
interface ConfigSuspicious {
354
354
( path : string , getContents : ( ref : string ) => Promise < string | undefined > ) : Promise < { suspect : string , sugestion ?: Suggestion } | undefined > ;
355
- [ basename : string ] : ( text : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
355
+ [ basename : string ] : ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => Promise < { suspect : string , suggestion ?: Suggestion } | undefined > ;
356
356
}
357
357
const configSuspicious = < ConfigSuspicious > ( async ( path , getContents ) => {
358
358
const basename = path . replace ( / .* \/ / , "" ) ;
359
359
const checker = configSuspicious [ basename ] ;
360
360
if ( ! checker ) return { suspect : `edited` } ;
361
- const text = await getContents ( "head" ) ;
361
+ const newText = await getContents ( "head" ) ;
362
362
// Removing tslint.json, tsconfig.json, package.json and
363
363
// OTHER_FILES.txt is checked by the CI. Specifics are in my commit
364
364
// message.
365
- if ( text === undefined ) return undefined ;
366
- return checker ( text , getContents ) ;
365
+ if ( newText === undefined ) return undefined ;
366
+ return checker ( newText , getContents ) ;
367
367
} ) ;
368
368
configSuspicious [ "OTHER_FILES.txt" ] = makeChecker (
369
369
[ ] ,
@@ -411,12 +411,12 @@ configSuspicious["tsconfig.json"] = makeChecker(
411
411
// to it, ignoring some keys. The ignored properties are in most cases checked
412
412
// elsewhere (dtslint), and in some cases they are irrelevant.
413
413
function makeChecker ( expectedForm : any , expectedFormUrl : string , options ?: { parse : ( text : string ) => unknown } | { ignore : ( data : any ) => void } ) {
414
- return async ( contents : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
414
+ return async ( newText : string , getContents : ( ref : string ) => Promise < string | undefined > ) => {
415
415
let suggestion : any ;
416
416
if ( options && "parse" in options ) {
417
- suggestion = options . parse ( contents ) ;
417
+ suggestion = options . parse ( newText ) ;
418
418
} else {
419
- try { suggestion = JSON . parse ( contents ) ; } catch ( e ) { if ( e instanceof SyntaxError ) return { suspect : `couldn't parse json: ${ e . message } ` } ; }
419
+ try { suggestion = JSON . parse ( newText ) ; } catch ( e ) { if ( e instanceof SyntaxError ) return { suspect : `couldn't parse json: ${ e . message } ` } ; }
420
420
}
421
421
const newData = jsonDiff . deepClone ( suggestion ) ;
422
422
if ( options && "ignore" in options ) options . ignore ( newData ) ;
@@ -465,7 +465,7 @@ function makeChecker(expectedForm: any, expectedFormUrl: string, options?: { par
465
465
? prettier . format ( JSON . stringify ( suggestion ) , { tabWidth : 4 , filepath : ".json" } )
466
466
: JSON . stringify ( suggestion , undefined , 4 ) + "\n"
467
467
) . split ( / ^ / m) ;
468
- const lines = contents . split ( / ^ / m) ;
468
+ const lines = newText . split ( / ^ / m) ;
469
469
// When suggestionLines is empty, that suggests removing all
470
470
// of the different lines
471
471
let startLine = 1 ;
0 commit comments