From d642e41ed5459b86a55b0db274a93adb2f7d907a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 14 Feb 2024 12:03:52 -0400 Subject: data: detect & report miscapitalization in commentary heading --- src/data/composite/wiki-data/withParsedCommentaryEntries.js | 4 ++-- src/data/validators.js | 13 +++++++++++-- src/data/yaml.js | 4 ++-- src/util/wiki-data.js | 8 ++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/data/composite/wiki-data/withParsedCommentaryEntries.js b/src/data/composite/wiki-data/withParsedCommentaryEntries.js index edfc9e3..f0404a5 100644 --- a/src/data/composite/wiki-data/withParsedCommentaryEntries.js +++ b/src/data/composite/wiki-data/withParsedCommentaryEntries.js @@ -2,7 +2,7 @@ import {input, templateCompositeFrom} from '#composite'; import find from '#find'; import {stitchArrays} from '#sugar'; import {isCommentary} from '#validators'; -import {commentaryRegex} from '#wiki-data'; +import {commentaryRegexCaseSensitive} from '#wiki-data'; import { fillMissingListItems, @@ -30,7 +30,7 @@ export default templateCompositeFrom({ [input('from')]: commentaryText, }) => continuation({ ['#rawMatches']: - Array.from(commentaryText.matchAll(commentaryRegex)), + Array.from(commentaryText.matchAll(commentaryRegexCaseSensitive)), }), }, diff --git a/src/data/validators.js b/src/data/validators.js index efe76fe..718e9c5 100644 --- a/src/data/validators.js +++ b/src/data/validators.js @@ -5,7 +5,8 @@ import printable_characters from 'printable-characters'; const {strlen} = printable_characters; import {colors, ENABLE_COLOR} from '#cli'; -import {commentaryRegex} from '#wiki-data'; +import {commentaryRegexCaseInsensitive, commentaryRegexCaseSensitive} + from '#wiki-data'; import { cut, @@ -302,7 +303,7 @@ export function isCommentary(commentaryText) { isContentString(commentaryText); const rawMatches = - Array.from(commentaryText.matchAll(commentaryRegex)); + Array.from(commentaryText.matchAll(commentaryRegexCaseInsensitive)); if (empty(rawMatches)) { throw new TypeError(`Expected at least one commentary heading`); @@ -332,6 +333,14 @@ export function isCommentary(commentaryText) { `(Check for missing "|-" in YAML, or a misshapen annotation)`); } + commentaryRegexCaseSensitive.lastIndex = 0; + if (!commentaryRegexCaseSensitive.test(ownInput)) { + throw new TypeError( + `Miscapitalization in commentary heading:\n` + + `${colors.red(`"${cut(ownInput, 60)}"`)}\n` + + `(Check for ${colors.red(`""`)} instead of ${colors.green(`""`)})`); + } + const nextHeading = (index === niceMatches.length - 1 ? commentaryText.length diff --git a/src/data/yaml.js b/src/data/yaml.js index 3b05d50..3bdba63 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -12,7 +12,7 @@ import {colors, ENABLE_COLOR, logInfo, logWarn} from '#cli'; import find, {bindFind, getAllFindSpecs} from '#find'; import Thing from '#thing'; import thingConstructors from '#things'; -import {commentaryRegex, sortByName} from '#wiki-data'; +import {commentaryRegexCaseSensitive, sortByName} from '#wiki-data'; import { annotateErrorWithFile, @@ -1189,7 +1189,7 @@ export function filterReferenceErrors(wikiData) { case '_commentary': if (value) { value = - Array.from(value.matchAll(commentaryRegex)) + Array.from(value.matchAll(commentaryRegexCaseSensitive)) .map(({groups}) => groups.artistReferences) .map(text => text.split(',').map(text => text.trim())); } diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index 1c1db6c..cc3bbba 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -665,8 +665,12 @@ export function sortFlashesChronologically(data, { // This regular expression *doesn't* match bodies, which will need to be parsed // out of the original string based on the indices matched using this. // -export const commentaryRegex = - /^(?.+?)(?:\|(?.+))?:<\/i>(?: \((?(?:.*?(?=,|\)[^)]*$))*?)(?:,? ?(?[a-zA-Z]+ [0-9]{1,2}, [0-9]{4,4}|[0-9]{1,2} [^,]*[0-9]{4,4}|[0-9]{1,4}[-/][0-9]{1,4}[-/][0-9]{1,4}))?\))?/gm; +const commentaryRegexRaw = + String.raw`^(?.+?)(?:\|(?.+))?:<\/i>(?: \((?(?:.*?(?=,|\)[^)]*$))*?)(?:,? ?(?[a-zA-Z]+ [0-9]{1,2}, [0-9]{4,4}|[0-9]{1,2} [^,]*[0-9]{4,4}|[0-9]{1,4}[-/][0-9]{1,4}[-/][0-9]{1,4}))?\))?`; +export const commentaryRegexCaseInsensitive = + new RegExp(commentaryRegexRaw, 'gmi'); +export const commentaryRegexCaseSensitive = + new RegExp(commentaryRegexRaw, 'gm'); export function filterAlbumsByCommentary(albums) { return albums -- cgit 1.3.0-6-gf8a5