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/validators.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/data/validators.js') 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(`""`)} instead of ${colors.green(`""`)})`); + } + const nextHeading = (index === niceMatches.length - 1 ? commentaryText.length -- cgit 1.3.0-6-gf8a5