Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit 3b44fa6

Browse files
committed
Cosmetic
1 parent 4183e39 commit 3b44fa6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/pr-info.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ async function getPackageInfosEtc(
354354
return { pkgInfo: result, popularityLevel: downloadsToPopularityLevel(maxDownloads) };
355355
}
356356

357-
async function categorizeFile(path: string, contents: (ref: string) => Promise<string | undefined>): Promise<[string|null, FileInfo]> {
357+
async function categorizeFile(path: string, getContents: (ref: string) => Promise<string | undefined>): Promise<[string|null, FileInfo]> {
358358
// https://regex101.com/r/eFvtrz/1
359359
const match = /^types\/(.*?)\/.*?[^\/](?:\.(d\.ts|tsx?|md))?$/.exec(path);
360360
if (!match) return [null, { path, kind: "infrastructure" }];
@@ -364,26 +364,26 @@ async function categorizeFile(path: string, contents: (ref: string) => Promise<s
364364
case "ts": case "tsx": return [pkg, { path, kind: "test" }];
365365
case "md": return [pkg, { path, kind: "markdown" }];
366366
default:
367-
const suspect = await configSuspicious(path, contents);
367+
const suspect = await configSuspicious(path, getContents);
368368
return [pkg, { path, kind: suspect ? "package-meta" : "package-meta-ok", ...suspect }];
369369
}
370370
}
371371

372372
interface ConfigSuspicious {
373373
(path: string, getContents: (ref: string) => Promise<string | undefined>): Promise<{ suspect: string, sugestion?: Suggestion } | undefined>;
374-
[basename: string]: (text: string, getContents: (ref: string) => Promise<string | undefined>) => Promise<{ suspect: string, suggestion?: Suggestion } | undefined>;
374+
[basename: string]: (newText: string, getContents: (ref: string) => Promise<string | undefined>) => Promise<{ suspect: string, suggestion?: Suggestion } | undefined>;
375375
};
376376
const configSuspicious = <ConfigSuspicious>(async (path, getContents) => {
377377
const basename = path.replace(/.*\//, "");
378-
if (!(basename in configSuspicious)) return { suspect: `edited` };
379-
const text = await getContents("head");
380-
if (text === undefined) return { suspect: `couldn't fetch contents` };
381378
const tester = configSuspicious[basename];
382-
return tester(text, getContents);
379+
if (!tester) return { suspect: `edited` };
380+
const newText = await getContents("head");
381+
if (newText === undefined) return { suspect: `couldn't fetch contents` };
382+
return tester(newText, getContents);
383383
});
384-
configSuspicious["OTHER_FILES.txt"] = async contents =>
384+
configSuspicious["OTHER_FILES.txt"] = async newText =>
385385
// not empty
386-
(contents.length === 0) ? { suspect: "empty" }
386+
(newText.length === 0) ? { suspect: "empty" }
387387
: undefined;
388388
configSuspicious["package.json"] = makeJsonCheckerFromCore(
389389
{ private: true },
@@ -414,9 +414,9 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
414414
// to it, ignoring some keys (JSON Patch paths). The ignored properties are in most cases checked
415415
// elsewhere (dtslint), and in some cases they are irrelevant.
416416
function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[]) {
417-
return async (contents: string, getContents: (ref: string) => Promise<string | undefined>) => {
417+
return async (newText: string, getContents: (ref: string) => Promise<string | undefined>) => {
418418
let suggestion: any;
419-
try { suggestion = JSON.parse(contents); } catch (e) { return { suspect: "couldn't parse json" }; }
419+
try { suggestion = JSON.parse(newText); } catch (e) { return { suspect: "couldn't parse json" }; }
420420
const newJson = jsonDiff.deepClone(suggestion);
421421
jsonDiff.applyPatch(newJson, ignoredKeys.map(path => ({ op: "remove", path })));
422422
const towardsIt = jsonDiff.deepClone(requiredForm);
@@ -459,7 +459,7 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[]) {
459459
? prettier.format(JSON.stringify(suggestion), { tabWidth: 4, filepath: ".json" })
460460
: JSON.stringify(suggestion, undefined, 4) + "\n"
461461
).split(/^/m);
462-
const lines = contents.split(/^/m);
462+
const lines = newText.split(/^/m);
463463
// When suggestionLines is empty, that suggests removing all
464464
// of the different lines
465465
let startLine = 1;

0 commit comments

Comments
 (0)