diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-02-16 18:04:24 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-02-17 17:09:18 -0400 |
commit | 693fa5da156f7879bf63327fc54fb5e4f1e57e6c (patch) | |
tree | edbd47bdffabae28a4899f693d73c2c0646ae8fb | |
parent | 2e5c82d427df107f98d319a6379da899b1b5d1b2 (diff) |
data-checks: factor out fieldPropertyMessage logic
-rw-r--r-- | src/data/checks.js | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/data/checks.js b/src/data/checks.js index e98f04de..336cd64c 100644 --- a/src/data/checks.js +++ b/src/data/checks.js @@ -127,6 +127,22 @@ function bindFindArtistOrAlias(boundFind) { }; } +function getFieldPropertyMessage(yamlDocumentSpec, property) { + const {fields} = yamlDocumentSpec; + + const field = + Object.entries(fields ?? {}) + .find(([field, fieldSpec]) => fieldSpec.property === property) + ?.[0]; + + const fieldPropertyMessage = + (field + ? ` in field ${colors.green(field)}` + : ` in property ${colors.green(property)}`); + + return fieldPropertyMessage; +} + // 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 @@ -306,17 +322,10 @@ export function filterReferenceErrors(wikiData, { return false; }, fn); - const {fields} = thing.constructor[Thing.yamlDocumentSpec]; - - const field = - Object.entries(fields ?? {}) - .find(([field, fieldSpec]) => fieldSpec.property === property) - ?.[0]; - const fieldPropertyMessage = - (field - ? ` in field ${colors.green(field)}` - : ` in property ${colors.green(property)}`); + getFieldPropertyMessage( + thing.constructor[Thing.yamlDocumentSpec], + property); const findFnMessage = (findFnKey.startsWith('_') |