From 693fa5da156f7879bf63327fc54fb5e4f1e57e6c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 16 Feb 2024 18:04:24 -0400 Subject: data-checks: factor out fieldPropertyMessage logic --- src/data/checks.js | 29 +++++++++++++++++++---------- 1 file 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('_') -- cgit 1.3.0-6-gf8a5