From 91811f63b5100b35a52abd8da550ffcd693a7efd Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 3 Dec 2023 14:23:20 +0200 Subject: [PATCH] lint: Fix JSdocs --- .eslintrc.js | 24 +++++++++++++----------- public/script.js | 9 +++++++++ public/scripts/loader.js | 2 +- public/scripts/stats.js | 15 +++------------ public/scripts/tags.js | 11 ++++++++++- 5 files changed, 36 insertions(+), 25 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index cf8a59375..faafd14c6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,31 +1,31 @@ module.exports = { root: true, extends: [ - 'eslint:recommended' + 'eslint:recommended', ], env: { - es6: true + es6: true, }, parserOptions: { - ecmaVersion: 'latest' + ecmaVersion: 'latest', }, overrides: [ { // Server-side files (plus this configuration file) files: ['src/**/*.js', 'server.js', '.eslintrc.js'], env: { - node: true - } + node: true, + }, }, { // Browser-side files files: ['public/**/*.js'], env: { browser: true, - jquery: true + jquery: true, }, parserOptions: { - sourceType: 'module' + sourceType: 'module', }, // These scripts are loaded in HTML; tell ESLint not to complain about them being undefined globals: { @@ -41,9 +41,9 @@ module.exports = { showdown: 'readonly', showdownKatex: 'readonly', SVGInject: 'readonly', - toastr: 'readonly' - } - } + toastr: 'readonly', + }, + }, ], // There are various vendored libraries that shouldn't be linted ignorePatterns: ['public/lib/**/*', '*.min.js', 'src/ai_horde/**/*'], @@ -56,9 +56,11 @@ module.exports = { 'semi': ['error', 'always'], 'indent': ['error', 4, { SwitchCase: 1, FunctionDeclaration: { parameters: 'first' } }], 'comma-dangle': ['error', 'always-multiline'], + 'eol-last': ['error', 'always'], + 'no-trailing-spaces': 'error', // These rules should eventually be enabled. 'no-async-promise-executor': 'off', 'no-inner-declarations': 'off', - } + }, }; diff --git a/public/script.js b/public/script.js index 369bce7af..04a035b75 100644 --- a/public/script.js +++ b/public/script.js @@ -6261,6 +6261,15 @@ function onScenarioOverrideRemoveClick() { $(this).closest('.scenario_override').find('.chat_scenario').val('').trigger('input'); } +/** + * Displays a blocking popup with a given text and type. + * @param {JQuery|string|Element} text - Text to display in the popup. + * @param {string} type + * @param {string} inputValue - Value to set the input to. + * @param {PopupOptions} options - Options for the popup. + * @typedef {{okButton?: string, rows?: number, wide?: boolean, large?: boolean }} PopupOptions - Options for the popup. + * @returns + */ function callPopup(text, type, inputValue = '', { okButton, rows, wide, large } = {}) { dialogueCloseStop = true; if (type) { diff --git a/public/scripts/loader.js b/public/scripts/loader.js index ed76619e5..534bd1609 100644 --- a/public/scripts/loader.js +++ b/public/scripts/loader.js @@ -25,4 +25,4 @@ export function hideLoader() { 'filter': 'blur(15px)', 'opacity': '0', }); -} \ No newline at end of file +} diff --git a/public/scripts/stats.js b/public/scripts/stats.js index 395e84c36..b8ff904ea 100644 --- a/public/scripts/stats.js +++ b/public/scripts/stats.js @@ -127,15 +127,13 @@ function createHtml(statsType, stats) { /** * Handles the user stats by getting them from the server, calculating the total and generating the HTML report. - * - * @param {Object} charStats - Object containing character statistics. */ async function userStatsHandler() { // Get stats from server await getStats(); // Calculate total stats - let totalStats = calculateTotalStats(charStats); + let totalStats = calculateTotalStats(); // Create HTML with stats createHtml('User', totalStats); @@ -144,7 +142,6 @@ async function userStatsHandler() { /** * Handles the character stats by getting them from the server and generating the HTML report. * - * @param {Object} charStats - Object containing character statistics. * @param {Object} characters - Object containing character data. * @param {string} this_chid - The character id. */ @@ -173,9 +170,6 @@ async function characterStatsHandler(characters, this_chid) { /** * Fetches the character stats from the server. - * - * @param {Object} charStats - Object containing character statistics. - * @returns {Object} - Object containing fetched character statistics. */ async function getStats() { const response = await fetch('/getstats', { @@ -231,13 +225,11 @@ function calculateGenTime(gen_started, gen_finished) { } let startDate = new Date(gen_started); let endDate = new Date(gen_finished); - return endDate - startDate; + return endDate.getTime() - startDate.getTime(); } /** * Sends a POST request to the server to update the statistics. - * - * @param {Object} stats - The stats data to update. */ async function updateStats() { const response = await fetch('/updatestats', { @@ -248,7 +240,7 @@ async function updateStats() { if (response.status !== 200) { console.error('Failed to update stats'); - console.log(response).status; + console.log(response.status); } } @@ -271,7 +263,6 @@ function countWords(str) { * @param {string} type - The type of the message processing (e.g., 'append', 'continue', 'appendFinal', 'swipe'). * @param {Object} characters - Object containing character data. * @param {string} this_chid - The character id. - * @param {Object} charStats - Object containing character statistics. * @param {string} oldMesssage - The old message that's being processed. */ async function statMesProcess(line, type, characters, this_chid, oldMesssage) { diff --git a/public/scripts/tags.js b/public/scripts/tags.js index 7b906f849..f6a756278 100644 --- a/public/scripts/tags.js +++ b/public/scripts/tags.js @@ -8,7 +8,8 @@ import { entitiesFilter, printCharacters, } from '../script.js'; -import { FILTER_TYPES } from './filters.js'; +// eslint-disable-next-line no-unused-vars +import { FILTER_TYPES, FilterHelper } from './filters.js'; import { groupCandidatesFilter, groups, selected_group } from './group-chats.js'; import { download, onlyUnique, parseJsonFile, uuidv4 } from './utils.js'; @@ -283,6 +284,14 @@ function createNewTag(tagName) { return tag; } +/** + * Appends a tag to the list element. + * @param {string} listElement List element selector. + * @param {object} tag Tag object. + * @param {TagOptions} options Options for the tag. + * @typedef {{removable?: boolean, selectable?: boolean, action?: function, isGeneralList?: boolean}} TagOptions + * @returns {void} + */ function appendTagToList(listElement, tag, { removable, selectable, action, isGeneralList }) { if (!listElement) { return;