From 7c3dd75e6a1403a74c875f1301df75001e2d7000 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 2 Dec 2023 09:07:08 -0500 Subject: [PATCH 01/12] Enable no-fallthrough lint --- .eslintrc.js | 3 +-- public/scripts/world-info.js | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 4cf54ff58..993f5ed2e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -71,7 +71,6 @@ module.exports = { 'no-unsafe-finally': 'off', 'no-dupe-keys': 'off', 'no-irregular-whitespace': 'off', - 'no-regex-spaces': 'off', - 'no-fallthrough': 'off' + 'no-regex-spaces': 'off' } }; diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 437ce3df7..a267378b3 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -1908,6 +1908,7 @@ async function checkWorldInfo(chat, maxContext) { entries: [entry.content] }); } + break; default: break; } From 12cdb76a2058088ec4a1a8a3501ffca7dbb5d90d Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 2 Dec 2023 09:09:22 -0500 Subject: [PATCH 02/12] Enable no-regex-spaces lint I noticed the old code was replacing two spaces with one space, over and over. Instead, I changed it to remove all consecutive strings of spaces just once, using the "+" quantifier. This should behave the same but is nicer to read and faster. --- .eslintrc.js | 3 +-- src/stable-diffusion.js | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 993f5ed2e..b5d706119 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -70,7 +70,6 @@ module.exports = { 'no-empty': 'off', 'no-unsafe-finally': 'off', 'no-dupe-keys': 'off', - 'no-irregular-whitespace': 'off', - 'no-regex-spaces': 'off' + 'no-irregular-whitespace': 'off' } }; diff --git a/src/stable-diffusion.js b/src/stable-diffusion.js index fd6a9c8fb..049685280 100644 --- a/src/stable-diffusion.js +++ b/src/stable-diffusion.js @@ -12,9 +12,7 @@ const writeFileAtomicSync = require('write-file-atomic').sync; */ function safeStr(x) { x = String(x); - for (let i = 0; i < 16; i++) { - x = x.replace(/ /g, ' '); - } + x = x.replace(/ +/g, ' '); x = x.trim(); x = x.replace(/^[\s,.]+|[\s,.]+$/g, ''); return x; From 8c89f373fa703b025a574cffb45db11a45fa7ee0 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 2 Dec 2023 09:10:41 -0500 Subject: [PATCH 03/12] Enable no-irregular-whitespace lint A couple comments contained non-breaking spaces (I think), which I replaced with regular spaces. --- .eslintrc.js | 3 +-- server.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index b5d706119..d8877020b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -69,7 +69,6 @@ module.exports = { 'no-constant-condition': 'off', 'no-empty': 'off', 'no-unsafe-finally': 'off', - 'no-dupe-keys': 'off', - 'no-irregular-whitespace': 'off' + 'no-dupe-keys': 'off' } }; diff --git a/server.js b/server.js index 9ff08178e..750894bc0 100644 --- a/server.js +++ b/server.js @@ -1285,10 +1285,10 @@ async function charaWrite(img_url, data, target_img, response = undefined, mes = for (let tEXtChunk of tEXtChunks) { chunks.splice(chunks.indexOf(tEXtChunk), 1); } - // Add new chunks before the IEND chunk + // Add new chunks before the IEND chunk const base64EncodedData = Buffer.from(data, 'utf8').toString('base64'); chunks.splice(-1, 0, PNGtext.encode('chara', base64EncodedData)); - //chunks.splice(-1, 0, text.encode('lorem', 'ipsum')); + //chunks.splice(-1, 0, text.encode('lorem', 'ipsum')); writeFileAtomicSync(charactersPath + target_img + '.png', Buffer.from(encode(chunks))); if (response !== undefined) response.send(mes); From e7ae1c47872971c3c74dcad3025a01f73991dc73 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 2 Dec 2023 09:11:02 -0500 Subject: [PATCH 04/12] Enable no-dupe-keys lint --- .eslintrc.js | 3 +-- public/scripts/stats.js | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d8877020b..6574d57e1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -68,7 +68,6 @@ module.exports = { 'no-unsafe-negation': 'off', 'no-constant-condition': 'off', 'no-empty': 'off', - 'no-unsafe-finally': 'off', - 'no-dupe-keys': 'off' + 'no-unsafe-finally': 'off' } }; diff --git a/public/scripts/stats.js b/public/scripts/stats.js index e62b6e883..938704377 100644 --- a/public/scripts/stats.js +++ b/public/scripts/stats.js @@ -288,7 +288,6 @@ async function statMesProcess(line, type, characters, this_chid, oldMesssage) { user_word_count: 0, non_user_msg_count: 0, user_msg_count: 0, - non_user_msg_count: 0, total_swipe_count: 0, date_first_chat: Date.now(), date_last_chat: Date.now(), From 367f3dba27ca1bb2ffaea0a71b20f87321949d7c Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 2 Dec 2023 09:12:38 -0500 Subject: [PATCH 05/12] Enable no-unsafe-finally lint --- .eslintrc.js | 3 +-- public/scripts/group-chats.js | 4 +--- public/scripts/openai.js | 4 +--- src/assets.js | 4 +--- src/sprites.js | 4 +--- 5 files changed, 5 insertions(+), 14 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 6574d57e1..3f9e55ba8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -67,7 +67,6 @@ module.exports = { 'no-self-assign': 'off', 'no-unsafe-negation': 'off', 'no-constant-condition': 'off', - 'no-empty': 'off', - 'no-unsafe-finally': 'off' + 'no-empty': 'off' } }; diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index 89244f0f3..e3441fe12 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -1604,9 +1604,7 @@ export async function getGroupPastChats(groupId) { } catch (err) { console.error(err); } - finally { - return chats; - } + return chats; } export async function openGroupChat(groupId, chatId) { diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 3adccfe6b..21f643572 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -1696,9 +1696,7 @@ async function calculateLogitBias() { result = {}; console.error(err); } - finally { - return result; - } + return result; } class TokenHandler { diff --git a/src/assets.js b/src/assets.js index 572de8765..832eeb7b0 100644 --- a/src/assets.js +++ b/src/assets.js @@ -118,9 +118,7 @@ function registerEndpoints(app, jsonParser) { catch (err) { console.log(err); } - finally { - return response.send(output); - } + return response.send(output); }); /** diff --git a/src/sprites.js b/src/sprites.js index d51adfc8a..ba25eee2c 100644 --- a/src/sprites.js +++ b/src/sprites.js @@ -133,9 +133,7 @@ function registerEndpoints(app, jsonParser, urlencodedParser) { catch (err) { console.log(err); } - finally { - return response.send(sprites); - } + return response.send(sprites); }); app.post('/api/sprites/delete', jsonParser, async (request, response) => { From 60ac1aa1c70ab8b7ebf327845cade581b27500a9 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 2 Dec 2023 09:14:48 -0500 Subject: [PATCH 06/12] Enable no-empty lint --- .eslintrc.js | 3 +-- public/scripts/kai-settings.js | 4 +++- public/scripts/textgen-settings.js | 4 +++- server.js | 6 ++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 3f9e55ba8..6cc572aba 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -66,7 +66,6 @@ module.exports = { 'use-isnan': 'off', 'no-self-assign': 'off', 'no-unsafe-negation': 'off', - 'no-constant-condition': 'off', - 'no-empty': 'off' + 'no-constant-condition': 'off' } }; diff --git a/public/scripts/kai-settings.js b/public/scripts/kai-settings.js index 75c0fc10c..96bf8502e 100644 --- a/public/scripts/kai-settings.js +++ b/public/scripts/kai-settings.js @@ -66,7 +66,9 @@ export function formatKoboldUrl(value) { url.pathname = '/api'; } return url.toString(); - } catch { } // Just using URL as a validation check + } catch { + // Just using URL as a validation check + } return null; } diff --git a/public/scripts/textgen-settings.js b/public/scripts/textgen-settings.js index a23bec16f..427a289a1 100644 --- a/public/scripts/textgen-settings.js +++ b/public/scripts/textgen-settings.js @@ -174,7 +174,9 @@ function formatTextGenURL(value) { url.pathname = '/api'; } return url.toString(); - } catch { } // Just using URL as a validation check + } catch { + // Just using URL as a validation check + } return null; } diff --git a/server.js b/server.js index 750894bc0..7fa66ed9d 100644 --- a/server.js +++ b/server.js @@ -118,7 +118,9 @@ if (fs.existsSync(whitelistPath)) { try { let whitelistTxt = fs.readFileSync(whitelistPath, 'utf-8'); whitelist = whitelistTxt.split("\n").filter(ip => ip).map(ip => ip.trim()); - } catch (e) { } + } catch (e) { + // Ignore errors that may occur when reading the whitelist (e.g. permissions) + } } const whitelistMode = getConfigValue('whitelistMode', true); @@ -781,7 +783,7 @@ app.post("/getchat", jsonParser, function (request, response) { const lines = data.split('\n'); // Iterate through the array of strings and parse each line as JSON - const jsonData = lines.map((l) => { try { return JSON.parse(l); } catch (_) { } }).filter(x => x); + const jsonData = lines.map((l) => { try { return JSON.parse(l); } catch (_) { return; } }).filter(x => x); return response.send(jsonData); } catch (error) { console.error(error); From 7def71aef76b26175e9befa85de5e7536969d6a9 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 2 Dec 2023 09:16:11 -0500 Subject: [PATCH 07/12] Only enable no-constant-condition for non-loops "while (true)" is a useful pattern that eslint doesn't really need to flag as a problem. --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 6cc572aba..f9b7d6392 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -66,6 +66,6 @@ module.exports = { 'use-isnan': 'off', 'no-self-assign': 'off', 'no-unsafe-negation': 'off', - 'no-constant-condition': 'off' + 'no-constant-condition': ['error', {checkLoops: false}] } }; From c05aee8e72cd2d89bb4dd5e1d2ec1e99bea10704 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 2 Dec 2023 09:17:16 -0500 Subject: [PATCH 08/12] Enable no-unsafe-negation lint This actually fixes a bug--the old code was negating "audioData.type" --- .eslintrc.js | 1 - public/scripts/extensions/tts/index.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f9b7d6392..e120ea8c5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -65,7 +65,6 @@ module.exports = { 'no-case-declarations': 'off', 'use-isnan': 'off', 'no-self-assign': 'off', - 'no-unsafe-negation': 'off', 'no-constant-condition': ['error', {checkLoops: false}] } }; diff --git a/public/scripts/extensions/tts/index.js b/public/scripts/extensions/tts/index.js index a1f6b7a07..af434d37a 100644 --- a/public/scripts/extensions/tts/index.js +++ b/public/scripts/extensions/tts/index.js @@ -425,7 +425,7 @@ function completeCurrentAudioJob() { */ async function addAudioJob(response) { const audioData = await response.blob() - if (!audioData.type in ['audio/mpeg', 'audio/wav', 'audio/x-wav', 'audio/wave', 'audio/webm']) { + if (!(audioData.type in ['audio/mpeg', 'audio/wav', 'audio/x-wav', 'audio/wave', 'audio/webm'])) { throw `TTS received HTTP response with invalid data format. Expecting audio/mpeg, got ${audioData.type}` } audioJobQueue.push(audioData) From 9204a31d32e506f0a7e965c6a1bc54f0dc8a370e Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 2 Dec 2023 09:18:49 -0500 Subject: [PATCH 09/12] Enable no-self-assign lint --- .eslintrc.js | 1 - public/scripts/extensions/tts/elevenlabs.js | 1 - public/scripts/slash-commands.js | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index e120ea8c5..334b0fcce 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -64,7 +64,6 @@ module.exports = { 'require-yield': 'off', 'no-case-declarations': 'off', 'use-isnan': 'off', - 'no-self-assign': 'off', 'no-constant-condition': ['error', {checkLoops: false}] } }; diff --git a/public/scripts/extensions/tts/elevenlabs.js b/public/scripts/extensions/tts/elevenlabs.js index 4cb7813fe..032b1c9df 100644 --- a/public/scripts/extensions/tts/elevenlabs.js +++ b/public/scripts/extensions/tts/elevenlabs.js @@ -115,7 +115,6 @@ class ElevenLabsTtsProvider { await this.fetchTtsVoiceObjects().catch(error => { throw `TTS API key validation failed` }) - this.settings.apiKey = this.settings.apiKey console.debug(`Saved new API_KEY: ${this.settings.apiKey}`) $('#tts_status').text('') this.onSettingsChange() diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index ba4a717ea..d13e84221 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -1281,7 +1281,7 @@ export async function promptQuietForLoudResponse(who, text) { } else if (who === 'char') { text = characters[character_id].name + ": " + text; } else if (who === 'raw') { - text = text; + // We don't need to modify the text } //text = `${text}${power_user.instruct.enabled ? '' : '\n'}${(power_user.always_force_name2 && who != 'raw') ? characters[character_id].name + ":" : ""}` From 1c121f1ba5b0b777c1be6c75133096a0327792be Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 2 Dec 2023 09:19:35 -0500 Subject: [PATCH 10/12] Enable use-isnan lint --- .eslintrc.js | 1 - public/scripts/extensions/regex/index.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 334b0fcce..7753defe7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -63,7 +63,6 @@ module.exports = { 'no-extra-boolean-cast': 'off', 'require-yield': 'off', 'no-case-declarations': 'off', - 'use-isnan': 'off', 'no-constant-condition': ['error', {checkLoops: false}] } }; diff --git a/public/scripts/extensions/regex/index.js b/public/scripts/extensions/regex/index.js index bce655efb..97870a158 100644 --- a/public/scripts/extensions/regex/index.js +++ b/public/scripts/extensions/regex/index.js @@ -178,7 +178,7 @@ async function onRegexEditorOpenClick(existingId) { .filter(":checked") .map(function () { return parseInt($(this).val()) }) .get() - .filter((e) => e !== NaN) || [], + .filter((e) => !isNaN(e)) || [], disabled: editorHtml .find(`input[name="disabled"]`) From a665a4897d8127dfda52ffabf77e3356a3c57f8b Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 2 Dec 2023 09:22:01 -0500 Subject: [PATCH 11/12] Enable no-unused-labels lint I'm not sure why "esversion: 6" was at the top of the file. My best guess is that whoever initially created it was using jshint, which says "use 'esversion: 6'" if used to lint a file which contains ES6 code. Even then, the proper syntax would be a comment. --- .eslintrc.js | 1 - public/scripts/RossAscends-mods.js | 2 -- 2 files changed, 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7753defe7..58ad08dbf 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -59,7 +59,6 @@ module.exports = { 'no-extra-semi': 'off', 'no-undef': 'off', 'no-prototype-builtins': 'off', - 'no-unused-labels': 'off', 'no-extra-boolean-cast': 'off', 'require-yield': 'off', 'no-case-declarations': 'off', diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index bb73fac9d..87bc323aa 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -1,5 +1,3 @@ -esversion: 6 - import { Generate, characters, From a91694ebbce7d193993602c54cce69b274e0e591 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 2 Dec 2023 18:41:54 +0200 Subject: [PATCH 12/12] Change audio format check --- public/scripts/extensions/tts/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/scripts/extensions/tts/index.js b/public/scripts/extensions/tts/index.js index af434d37a..f43e192ff 100644 --- a/public/scripts/extensions/tts/index.js +++ b/public/scripts/extensions/tts/index.js @@ -421,12 +421,12 @@ function completeCurrentAudioJob() { /** * Accepts an HTTP response containing audio/mpeg data, and puts the data as a Blob() on the queue for playback - * @param {*} response + * @param {Response} response */ async function addAudioJob(response) { const audioData = await response.blob() - if (!(audioData.type in ['audio/mpeg', 'audio/wav', 'audio/x-wav', 'audio/wave', 'audio/webm'])) { - throw `TTS received HTTP response with invalid data format. Expecting audio/mpeg, got ${audioData.type}` + if (!audioData.type.startsWith('audio/')) { + throw `TTS received HTTP response with invalid data format. Expecting audio/*, got ${audioData.type}` } audioJobQueue.push(audioData) console.debug('Pushed audio job to queue.')