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

Commit 97d0bb2

Browse files
jablkoelibarzilay
authored andcommitted
Reuse JSON Patch to ignore keys
1 parent 9f7bb54 commit 97d0bb2

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/pr-info.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ configSuspicious["OTHER_FILES.txt"] = contents =>
382382
: undefined;
383383
configSuspicious["package.json"] = makeJsonCheckerFromCore(
384384
{ private: true },
385-
[ "dependencies", "types", "typesVersions" ]
385+
[ "/dependencies", "/types", "/typesVersions" ]
386386
);
387387
configSuspicious["tslint.json"] = makeJsonCheckerFromCore(
388388
{ extends: "dtslint/dt.json" },
@@ -402,20 +402,17 @@ configSuspicious["tsconfig.json"] = makeJsonCheckerFromCore(
402402
forceConsistentCasingInFileNames: true
403403
}
404404
},
405-
[ "files", "compilerOptions.paths", "compilerOptions.baseUrl", "compilerOptions.typeRoots" ]
405+
[ "/files", "/compilerOptions/paths", "/compilerOptions/baseUrl", "/compilerOptions/typeRoots" ]
406406
);
407407

408408
// helper for json file testers: allow either a given "requiredForm", or any edits that get closer
409-
// to it, ignoring some keys (sub-values can be specified using dots). The ignored properties are
410-
// in most cases checked elsewhere (dtslint), and in some cases they are irrelevant.
409+
// to it, ignoring some keys (JSON Patch paths). The ignored properties are in most cases checked
410+
// elsewhere (dtslint), and in some cases they are irrelevant.
411411
function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[]) {
412412
const diffFromReq = (text: string) => {
413413
let json: any;
414414
try { json = JSON.parse(text); } catch (e) { return "couldn't parse json"; }
415-
// allow dotted keys in ignoredKeys
416-
ignoredKeys.map(k => k.split(".")).forEach(keys =>
417-
delete keys.slice(0, -1).reduce((a,b) => a?.[b], json)
418-
?.[keys[keys.length - 1]]);
415+
jsonDiff.applyPatch(json, ignoredKeys.map(path => ({ op: "remove", path })));
419416
try { return jsonDiff.compare(requiredForm, json); } catch (e) { return "couldn't diff json" };
420417
};
421418
return (contents: string, oldText?: string) => {

0 commit comments

Comments
 (0)