diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-02-16 16:10:09 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-02-17 17:09:18 -0400 |
commit | 2e5c82d427df107f98d319a6379da899b1b5d1b2 (patch) | |
tree | 73b1d1063787a9c2a4c58f8c05bbe1be981ca13e /src | |
parent | b7debd668d03b2236cea1b0291acb8efc6f3ee0d (diff) |
data-checks: factor out findArtistOrAlias logic
Diffstat (limited to 'src')
-rw-r--r-- | src/data/checks.js | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/data/checks.js b/src/data/checks.js index 96f4cd8c..e98f04de 100644 --- a/src/data/checks.js +++ b/src/data/checks.js @@ -113,6 +113,20 @@ export function reportDuplicateDirectories(wikiData, { }); } +function bindFindArtistOrAlias(boundFind) { + return artistRef => { + const alias = boundFind.artistAlias(artistRef, {mode: 'quiet'}); + if (alias) { + // No need to check if the original exists here. Aliases are automatically + // created from a field on the original, so the original certainly exists. + const original = alias.aliasedArtist; + throw new Error(`Reference ${colors.red(artistRef)} is to an alias, should be ${colors.green(original.name)}`); + } + + return boundFind.artist(artistRef); + }; +} + // Warn about references across data which don't match anything. This involves // using the find() functions on all references, setting it to 'error' mode, and // collecting everything in a structured logged (which gets logged if there are @@ -168,18 +182,7 @@ export function filterReferenceErrors(wikiData, { ]; const boundFind = bindFind(wikiData, {mode: 'error'}); - - const findArtistOrAlias = artistRef => { - const alias = boundFind.artistAlias(artistRef, {mode: 'quiet'}); - if (alias) { - // No need to check if the original exists here. Aliases are automatically - // created from a field on the original, so the original certainly exists. - const original = alias.aliasedArtist; - throw new Error(`Reference ${colors.red(artistRef)} is to an alias, should be ${colors.green(original.name)}`); - } - - return boundFind.artist(artistRef); - }; + const findArtistOrAlias = bindFindArtistOrAlias(boundFind); const aggregate = openAggregate({message: `Errors validating between-thing references in data`}); for (const [thingDataProp, propSpec] of referenceSpec) { |