« get me outta code hell

data: detect & report miscapitalization in commentary heading - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-02-14 12:03:52 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-02-14 13:35:33 -0400
commitd642e41ed5459b86a55b0db274a93adb2f7d907a (patch)
tree8652a41fc631ad765cb07ae40fd1a1c08a2f6ace /src/data
parent9b13c1eb3766aeec4be518a755b209d6e0cdfd42 (diff)
data: detect & report miscapitalization in commentary heading
Diffstat (limited to 'src/data')
-rw-r--r--src/data/composite/wiki-data/withParsedCommentaryEntries.js4
-rw-r--r--src/data/validators.js13
-rw-r--r--src/data/yaml.js4
3 files changed, 15 insertions, 6 deletions
diff --git a/src/data/composite/wiki-data/withParsedCommentaryEntries.js b/src/data/composite/wiki-data/withParsedCommentaryEntries.js
index edfc9e3c..f0404a5d 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 efe76fe0..718e9c57 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(`"<I>"`)} instead of ${colors.green(`"<i>"`)})`);
+    }
+
     const nextHeading =
       (index === niceMatches.length - 1
         ? commentaryText.length
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 3b05d505..3bdba638 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()));
                 }