Skip to content

Commit 710f7ab

Browse files
fix: Address ESLint errors in verify-locale-strings.js
Fixed all linting issues: **require-unicode-regexp**: Added 'u' flag to all regex patterns - Line 50: escapeRegex function - Line 68: buildExceptionsRegex return - Lines 84-85: hasTitleCaseViolation quote removal - Line 89: hasTitleCaseViolation word split - Lines 97, 100: Title case pattern checks - Lines 190, 198: convertToSentenceCase quote replacement - Line 206: convertToSentenceCase word split **no-plusplus**: Replaced ++ with += 1 - Lines 193, 201: placeholderIndex increments **no-shadow**: Fixed variable shadowing - Line 227: Renamed destructured 'text' to 'quotedText' to avoid shadowing the outer 'text' parameter All changes verified - script still passes validation tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 056f18f commit 710f7ab

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

development/verify-locale-strings.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function buildExceptionsRegex(exceptions) {
4747
const patterns = [];
4848

4949
// Escape special regex characters for exact matches
50-
const escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
50+
const escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
5151

5252
// Add exact matches (escaped to treat as literals)
5353
exceptions.exactMatches.forEach((term) => {
@@ -65,7 +65,7 @@ function buildExceptionsRegex(exceptions) {
6565
});
6666

6767
// Combine all patterns with OR operator
68-
return new RegExp(patterns.join('|'));
68+
return new RegExp(patterns.join('|'), 'u');
6969
}
7070

7171
// Pre-compile the exceptions regex once at module load time
@@ -81,23 +81,23 @@ function containsSpecialCase(text) {
8181
function hasTitleCaseViolation(text) {
8282
// Remove quoted text (single quotes and escaped double quotes) before checking
8383
// Quoted text refers to UI elements and should preserve capitalization
84-
let textWithoutQuotes = text.replace(/'[^']*'/g, ''); // Remove 'text'
85-
textWithoutQuotes = textWithoutQuotes.replace(/\\"[^"]*\\"/g, ''); // Remove \"text\"
84+
let textWithoutQuotes = text.replace(/'[^']*'/gu, ''); // Remove 'text'
85+
textWithoutQuotes = textWithoutQuotes.replace(/\\"[^"]*\\"/gu, ''); // Remove \"text\"
8686

8787
// Ignore single words (filter out empty strings from whitespace)
8888
const words = textWithoutQuotes
89-
.split(/\s+/)
89+
.split(/\s+/u)
9090
.filter((word) => word.length > 0);
9191
if (words.length < 2) {
9292
return false;
9393
}
9494

9595
// Check if multiple words start with capital letters (Title Case pattern)
9696
// This pattern: "Word Word" or "Word Word Word"
97-
const titleCasePattern = /^([A-Z][a-z]+\s+)+[A-Z][a-z]+/;
97+
const titleCasePattern = /^([A-Z][a-z]+\s+)+[A-Z][a-z]+/u;
9898

9999
// Also catch patterns like "In Progress", "Not Available"
100-
const multipleCapsPattern = /\b[A-Z][a-z]+\s+[A-Z][a-z]+\b/;
100+
const multipleCapsPattern = /\b[A-Z][a-z]+\s+[A-Z][a-z]+\b/u;
101101

102102
return (
103103
titleCasePattern.test(textWithoutQuotes) ||
@@ -187,23 +187,23 @@ function convertToSentenceCase(text) {
187187
let placeholderIndex = 0;
188188

189189
// Find all single-quoted text and replace with unique placeholders
190-
textToProcess = textToProcess.replace(/'([^']*)'/g, (match) => {
190+
textToProcess = textToProcess.replace(/'([^']*)'/gu, (match) => {
191191
const uniquePlaceholder = `___QUOTED_${placeholderIndex}___`;
192192
quotedTexts.push({ placeholder: uniquePlaceholder, text: match });
193-
placeholderIndex++;
193+
placeholderIndex += 1;
194194
return uniquePlaceholder;
195195
});
196196

197197
// Find all escaped double-quoted text and replace with unique placeholders
198-
textToProcess = textToProcess.replace(/\\"([^"]*)\\"/g, (match) => {
198+
textToProcess = textToProcess.replace(/\\"([^"]*)\\"/gu, (match) => {
199199
const uniquePlaceholder = `___QUOTED_${placeholderIndex}___`;
200200
quotedTexts.push({ placeholder: uniquePlaceholder, text: match });
201-
placeholderIndex++;
201+
placeholderIndex += 1;
202202
return uniquePlaceholder;
203203
});
204204

205205
// Convert to sentence case
206-
const words = textToProcess.split(/\s+/).filter((word) => word.length > 0);
206+
const words = textToProcess.split(/\s+/u).filter((word) => word.length > 0);
207207
let converted = words
208208
.map((word, index) => {
209209
// Check if word contains a placeholder (exact match or with punctuation)
@@ -224,8 +224,8 @@ function convertToSentenceCase(text) {
224224
.join(' ');
225225

226226
// Restore quoted text with unique placeholders
227-
quotedTexts.forEach(({ placeholder, text }) => {
228-
converted = converted.replace(placeholder, text);
227+
quotedTexts.forEach(({ placeholder, text: quotedText }) => {
228+
converted = converted.replace(placeholder, quotedText);
229229
});
230230

231231
return converted;

0 commit comments

Comments
 (0)