Skip to content

Commit

Permalink
fix: alphabetically sort pretty-printed DB (#1512)
Browse files Browse the repository at this point in the history
Makes it a lot easier to search for specific changes.

---------

Signed-off-by: github-actions <[email protected]>
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
rix0rrr and github-actions authored Dec 19, 2024
1 parent 410409a commit 0e20bf3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/@aws-cdk/service-spec-importers/src/diff-fmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export class DiffFormatter {
),
listWithCaption(
'resources',
this.dbs[db].follow('hasResource', s).map((e) => this.renderResource(e.entity, db).prefix([' '])),
[...this.dbs[db].follow('hasResource', s)]
.sort(sortByKey((e) => e.entity.name))
.map((e) => this.renderResource(e.entity, db).prefix([' '])),
),
]);
}
Expand Down Expand Up @@ -95,7 +97,9 @@ export class DiffFormatter {
listWithCaption('attributes', this.renderProperties(r.attributes, db)),
listWithCaption(
'types',
this.dbs[db].follow('usesType', r).map((e) => this.renderTypeDefinition(e.entity, db).prefix([' '])),
[...this.dbs[db].follow('usesType', r)]
.sort(sortByKey((e) => e.entity.name))
.map((e) => this.renderTypeDefinition(e.entity, db).prefix([' '])),
),
]);
}
Expand Down Expand Up @@ -291,3 +295,7 @@ function listWithCaption(caption: string, trees: PrintableTree[]) {
ret.addBullets(trees);
return ret.prefix([' '], [' ']);
}

function sortByKey<T>(keyFn: (x: T) => string): (a: T, b: T) => number {
return (a, b) => keyFn(a).localeCompare(keyFn(b));
}

0 comments on commit 0e20bf3

Please sign in to comment.