From a60b7e555d61f2daf2e5e83b17ccf339250cbf15 Mon Sep 17 00:00:00 2001 From: mARTin-B78 Date: Tue, 6 Oct 2026 03:32:10 +0200 Subject: [PATCH] fix(sonar): add localeCompare compare function to bare sort() calls (javascript:S2871) Co-Authored-By: Claude Sonnet 5.5 --- static/js/audiobook-cast.js | 2 +- static/js/library-characters.js | 4 ++-- static/js/voice-library.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/static/js/audiobook-cast.js b/static/js/audiobook-cast.js index df2e9fa..ae92644 100644 --- a/static/js/audiobook-cast.js +++ b/static/js/audiobook-cast.js @@ -7,7 +7,7 @@ function _abCastMarkdown(data) { const payload = data || {}; const segments = Array.isArray(payload.segments) ? payload.segments : []; - const speakers = [...new Set(segments.filter(s => s?.type === 'dialogue' && s.speaker).map(s => String(s.speaker)))].sort(); + const speakers = [...new Set(segments.filter(s => s?.type === 'dialogue' && s.speaker).map(s => String(s.speaker)))].sort((a, b) => a.localeCompare(b)); const lines = [`# ${payload.title || 'Cast Script'}`, '']; const metaBits = []; if (payload.savedAt) metaBits.push('exported ' + new Date(payload.savedAt).toISOString().slice(0, 16).replace('T', ' ')); diff --git a/static/js/library-characters.js b/static/js/library-characters.js index e1a0d57..01d0c48 100644 --- a/static/js/library-characters.js +++ b/static/js/library-characters.js @@ -237,7 +237,7 @@ async function libraryRenderCharacters(opts) { container.appendChild(bar); const searchQuery = inStudio ? '' : String(window._libCharsQuery || '').trim().toLowerCase(); - const bookNames = Object.keys(byBook).sort(); + const bookNames = Object.keys(byBook).sort((a, b) => a.localeCompare(b)); const head = document.createElement('div'); head.className = 'lib-chars-scope'; if (inStudio) { @@ -294,7 +294,7 @@ async function libraryRenderCharacters(opts) { const productions = document.createDocumentFragment(); let shownBands = 0; - Object.keys(byBook).sort().forEach(function (book, bandIndex) { + Object.keys(byBook).sort((a, b) => a.localeCompare(b)).forEach(function (book, bandIndex) { const chars = byBook[book].sort(_charSortCmp[sortMode] || _charSortCmp.tier); if (sortDir === 'desc') chars.reverse(); // Narrator stays pinned first regardless of sort — same convention as diff --git a/static/js/voice-library.js b/static/js/voice-library.js index e1ed5f5..39fc5b8 100644 --- a/static/js/voice-library.js +++ b/static/js/voice-library.js @@ -335,7 +335,7 @@ function populateLibraryFilters() { const sexOrder = ['F','M','N']; const sexes = [...sexSet] .sort((a, b) => (sexOrder.indexOf(a) < 0 ? 99 : sexOrder.indexOf(a)) - (sexOrder.indexOf(b) < 0 ? 99 : sexOrder.indexOf(b))); - const types = [...typeSet].sort(); + const types = [...typeSet].sort((a, b) => a.localeCompare(b)); const tags = [...tagSet].sort((a, b) => a.localeCompare(b)); const groups = [...groupSet].sort((a, b) => a.localeCompare(b)); const sig = JSON.stringify([langs, sexes, types, tags, groups]); @@ -3464,7 +3464,7 @@ function renderVoiceGroupsBar() { const g = (v.group || '').trim(); if (g) groups[g] = (groups[g] || 0) + 1; }); - const names = Object.keys(groups).sort(); + const names = Object.keys(groups).sort((a, b) => a.localeCompare(b)); if (!names.length) { bar.hidden = true; bar.innerHTML = ''; return; } bar.hidden = false; const active = window._voiceGroupFilter || '';