From fd27105c2c401e44aa66c393c072657db2584fb6 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Mon, 9 Sep 2024 20:01:25 +0200 Subject: [PATCH] eslint 8.57 WIP: * tweaking some more rules. * fixing linting. --- conversejs/build-conversejs-patch-i18n.js | 1 + conversejs/builtin.ts | 12 ++-- .../templates/muc-mam-search-app.js | 3 + .../templates/muc-mam-search-message.js | 3 + .../templates/muc-mam-search-occupant.js | 3 + .../plugins/notes/templates/muc-note-app.js | 3 + .../notes/templates/muc-note-occupant.js | 3 + .../plugins/notes/templates/muc-note.js | 3 + .../plugins/notes/templates/muc-notes.js | 3 + .../custom/plugins/poll/modals/poll-form.js | 3 + .../plugins/poll/templates/poll-form.js | 3 + .../custom/plugins/poll/templates/poll.js | 3 + .../tasks/modals/templates/pick-task-list.js | 3 + .../plugins/tasks/templates/muc-task-app.js | 3 + .../plugins/tasks/templates/muc-task-list.js | 3 + .../plugins/tasks/templates/muc-task-lists.js | 3 + .../plugins/tasks/templates/muc-task.js | 6 +- .../plugins/terms/components/muc-terms.js | 3 + .../livechat-external-login-modal.js | 8 ++- .../custom/templates/muc-bottom-panel.js | 3 + conversejs/custom/templates/muc-chatarea.js | 3 + conversejs/custom/templates/muc-head.js | 3 + conversejs/custom/templates/muc.js | 3 + conversejs/lib/auth.ts | 6 +- conversejs/lib/plugins/livechat-emojis.ts | 10 +-- .../livechat-specific/chatroom-message.ts | 3 +- .../lib/plugins/livechat-specific/chatroom.ts | 6 +- .../livechat-specific/message-action.ts | 2 +- .../lib/plugins/livechat-specific/toolbar.ts | 3 + .../lib/plugins/livechat-specific/utils.ts | 2 +- .../lib/plugins/livechat-viewer-mode.ts | 10 +-- conversejs/lib/plugins/slow-mode.ts | 8 ++- conversejs/lib/utils.ts | 2 +- eslint.config.mjs | 65 ++++++++++++++++--- 34 files changed, 165 insertions(+), 36 deletions(-) diff --git a/conversejs/build-conversejs-patch-i18n.js b/conversejs/build-conversejs-patch-i18n.js index ea87d7c3..7eff43d0 100644 --- a/conversejs/build-conversejs-patch-i18n.js +++ b/conversejs/build-conversejs-patch-i18n.js @@ -4,6 +4,7 @@ // // SPDX-License-Identifier: AGPL-3.0-only +/* eslint-disable @typescript-eslint/no-require-imports */ const fs = require('node:fs') const path = require('node:path') const YAML = require('yaml') diff --git a/conversejs/builtin.ts b/conversejs/builtin.ts index 9cb1cc5a..28cfc320 100644 --- a/conversejs/builtin.ts +++ b/conversejs/builtin.ts @@ -2,6 +2,8 @@ // // SPDX-License-Identifier: AGPL-3.0-only +/* eslint-disable @typescript-eslint/no-unsafe-function-type */ + import type { InitConverseJSParams, ChatIncludeMode, ExternalAuthResult } from 'shared/lib/types' import { inIframe } from './lib/utils' import { initDom } from './lib/dom' @@ -39,7 +41,7 @@ declare global { } initConversePlugins: typeof initConversePlugins initConverse: typeof initConverse - reconnectConverse?: (room: string) => void + reconnectConverse?: (params: any) => void externalAuthGetResult?: (data: ExternalAuthResult) => void } } @@ -86,7 +88,7 @@ window.initConversePlugins = initConversePlugins async function initConverse ( initConverseParams: InitConverseJSParams, chatIncludeMode: ChatIncludeMode = 'chat-only', - peertubeAuthHeader?: { [header: string]: string } | null + peertubeAuthHeader?: Record | null ): Promise { // First, fixing relative websocket urls. if (initConverseParams.localWebsocketServiceUrl?.startsWith('/')) { @@ -121,9 +123,9 @@ async function initConverse ( params.view_mode = chatIncludeMode === 'chat-only' ? 'fullscreen' : 'embedded' params.allow_url_history_change = chatIncludeMode === 'chat-only' - let isAuthenticated: boolean = false - let isAuthenticatedWithExternalAccount: boolean = false - let isRemoteWithNicknameSet: boolean = false + let isAuthenticated = false + let isAuthenticatedWithExternalAccount = false + let isRemoteWithNicknameSet = false // OIDC (OpenID Connect): const tryOIDC = (initConverseParams.externalAuthOIDC?.length ?? 0) > 0 diff --git a/conversejs/custom/plugins/mam-search/templates/muc-mam-search-app.js b/conversejs/custom/plugins/mam-search/templates/muc-mam-search-app.js index 8e3a9e10..2182f7ad 100644 --- a/conversejs/custom/plugins/mam-search/templates/muc-mam-search-app.js +++ b/conversejs/custom/plugins/mam-search/templates/muc-mam-search-app.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { converseLocalizedHelpUrl } from '../../../shared/lib/help' import { tplMUCApp } from '../../../shared/components/muc-app/templates/muc-app.js' import { html } from 'lit' diff --git a/conversejs/custom/plugins/mam-search/templates/muc-mam-search-message.js b/conversejs/custom/plugins/mam-search/templates/muc-mam-search-message.js index 5c9596c1..d345ea8a 100644 --- a/conversejs/custom/plugins/mam-search/templates/muc-mam-search-message.js +++ b/conversejs/custom/plugins/mam-search/templates/muc-mam-search-message.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { html } from 'lit' /** diff --git a/conversejs/custom/plugins/mam-search/templates/muc-mam-search-occupant.js b/conversejs/custom/plugins/mam-search/templates/muc-mam-search-occupant.js index 51c5ef35..6d9553a9 100644 --- a/conversejs/custom/plugins/mam-search/templates/muc-mam-search-occupant.js +++ b/conversejs/custom/plugins/mam-search/templates/muc-mam-search-occupant.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { html } from 'lit' import { api } from '@converse/headless' import { getAuthorStyle } from '../../../../src/utils/color.js' diff --git a/conversejs/custom/plugins/notes/templates/muc-note-app.js b/conversejs/custom/plugins/notes/templates/muc-note-app.js index e63f6e24..3ce7c093 100644 --- a/conversejs/custom/plugins/notes/templates/muc-note-app.js +++ b/conversejs/custom/plugins/notes/templates/muc-note-app.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { converseLocalizedHelpUrl } from '../../../shared/lib/help' import { tplMUCApp } from '../../../shared/components/muc-app/templates/muc-app.js' import { html } from 'lit' diff --git a/conversejs/custom/plugins/notes/templates/muc-note-occupant.js b/conversejs/custom/plugins/notes/templates/muc-note-occupant.js index 72c50ff3..8dd28894 100644 --- a/conversejs/custom/plugins/notes/templates/muc-note-occupant.js +++ b/conversejs/custom/plugins/notes/templates/muc-note-occupant.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { html } from 'lit' import { api } from '@converse/headless' import { getAuthorStyle } from '../../../../src/utils/color.js' diff --git a/conversejs/custom/plugins/notes/templates/muc-note.js b/conversejs/custom/plugins/notes/templates/muc-note.js index 16815e20..d900d442 100644 --- a/conversejs/custom/plugins/notes/templates/muc-note.js +++ b/conversejs/custom/plugins/notes/templates/muc-note.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { api } from '@converse/headless' import { html } from 'lit' import { __ } from 'i18n' diff --git a/conversejs/custom/plugins/notes/templates/muc-notes.js b/conversejs/custom/plugins/notes/templates/muc-notes.js index e488dea2..0e31d255 100644 --- a/conversejs/custom/plugins/notes/templates/muc-notes.js +++ b/conversejs/custom/plugins/notes/templates/muc-notes.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { html } from 'lit' import { repeat } from 'lit/directives/repeat.js' import { __ } from 'i18n' diff --git a/conversejs/custom/plugins/poll/modals/poll-form.js b/conversejs/custom/plugins/poll/modals/poll-form.js index d9746289..fc3fc0d9 100644 --- a/conversejs/custom/plugins/poll/modals/poll-form.js +++ b/conversejs/custom/plugins/poll/modals/poll-form.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { __ } from 'i18n' import BaseModal from 'plugins/modal/modal.js' import { api } from '@converse/headless' diff --git a/conversejs/custom/plugins/poll/templates/poll-form.js b/conversejs/custom/plugins/poll/templates/poll-form.js index 1009b254..d26d2629 100644 --- a/conversejs/custom/plugins/poll/templates/poll-form.js +++ b/conversejs/custom/plugins/poll/templates/poll-form.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { converseLocalizedHelpUrl } from '../../../shared/lib/help' import { html } from 'lit' import { __ } from 'i18n' diff --git a/conversejs/custom/plugins/poll/templates/poll.js b/conversejs/custom/plugins/poll/templates/poll.js index 152a0f32..d205eb70 100644 --- a/conversejs/custom/plugins/poll/templates/poll.js +++ b/conversejs/custom/plugins/poll/templates/poll.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { html } from 'lit' import { repeat } from 'lit/directives/repeat.js' import { __ } from 'i18n' diff --git a/conversejs/custom/plugins/tasks/modals/templates/pick-task-list.js b/conversejs/custom/plugins/tasks/modals/templates/pick-task-list.js index d872ae16..932c3083 100644 --- a/conversejs/custom/plugins/tasks/modals/templates/pick-task-list.js +++ b/conversejs/custom/plugins/tasks/modals/templates/pick-task-list.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { html } from 'lit' import { repeat } from 'lit/directives/repeat.js' import { __ } from 'i18n' diff --git a/conversejs/custom/plugins/tasks/templates/muc-task-app.js b/conversejs/custom/plugins/tasks/templates/muc-task-app.js index aeaf68e9..dde6a53d 100644 --- a/conversejs/custom/plugins/tasks/templates/muc-task-app.js +++ b/conversejs/custom/plugins/tasks/templates/muc-task-app.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { converseLocalizedHelpUrl } from '../../../shared/lib/help' import { tplMUCApp } from '../../../shared/components/muc-app/templates/muc-app.js' import { html } from 'lit' diff --git a/conversejs/custom/plugins/tasks/templates/muc-task-list.js b/conversejs/custom/plugins/tasks/templates/muc-task-list.js index 0de8494e..88c1a950 100644 --- a/conversejs/custom/plugins/tasks/templates/muc-task-list.js +++ b/conversejs/custom/plugins/tasks/templates/muc-task-list.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { html } from 'lit' import { repeat } from 'lit/directives/repeat.js' import { __ } from 'i18n' diff --git a/conversejs/custom/plugins/tasks/templates/muc-task-lists.js b/conversejs/custom/plugins/tasks/templates/muc-task-lists.js index d875f4c1..efb02185 100644 --- a/conversejs/custom/plugins/tasks/templates/muc-task-lists.js +++ b/conversejs/custom/plugins/tasks/templates/muc-task-lists.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { html } from 'lit' import { repeat } from 'lit/directives/repeat.js' import { __ } from 'i18n' diff --git a/conversejs/custom/plugins/tasks/templates/muc-task.js b/conversejs/custom/plugins/tasks/templates/muc-task.js index e003341a..7c8d02da 100644 --- a/conversejs/custom/plugins/tasks/templates/muc-task.js +++ b/conversejs/custom/plugins/tasks/templates/muc-task.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { html } from 'lit' import { __ } from 'i18n' @@ -20,7 +23,8 @@ export function tplMucTask (el, task) { type="checkbox" class="form-check-input" .checked=${done === true} - @click=${(_ev) => { + @click=${(ev) => { + ev?.preventDefault() task.set('done', !done) task.saveItem() }} diff --git a/conversejs/custom/plugins/terms/components/muc-terms.js b/conversejs/custom/plugins/terms/components/muc-terms.js index b133e64b..ee7d2468 100644 --- a/conversejs/custom/plugins/terms/components/muc-terms.js +++ b/conversejs/custom/plugins/terms/components/muc-terms.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { CustomElement } from 'shared/components/element.js' import { api } from '@converse/headless' import { html } from 'lit' diff --git a/conversejs/custom/templates/livechat-external-login-modal.js b/conversejs/custom/templates/livechat-external-login-modal.js index 0bba91de..a9c4f565 100644 --- a/conversejs/custom/templates/livechat-external-login-modal.js +++ b/conversejs/custom/templates/livechat-external-login-modal.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { _converse, api } from '@converse/headless' import { __ } from 'i18n' import { html } from 'lit' @@ -28,8 +31,9 @@ function externalLoginClickHandler (ev, el, externalAuthOIDCUrl) { console.log('Received an external authentication result...', data) if (!data.ok) { - // eslint-disable-next-line no-undef - el.external_auth_oidc_alert_message = __(LOC_login_external_auth_alert_message) + + el.external_auth_oidc_alert_message = + // eslint-disable-next-line no-undef + __(LOC_login_external_auth_alert_message) + (data.message ? ` (${data.message})` : '') return } diff --git a/conversejs/custom/templates/muc-bottom-panel.js b/conversejs/custom/templates/muc-bottom-panel.js index b1648b09..87c07f98 100644 --- a/conversejs/custom/templates/muc-bottom-panel.js +++ b/conversejs/custom/templates/muc-bottom-panel.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { __ } from 'i18n' import { _converse, api } from '@converse/headless' import { html } from 'lit' diff --git a/conversejs/custom/templates/muc-chatarea.js b/conversejs/custom/templates/muc-chatarea.js index d2067c4e..88eab651 100644 --- a/conversejs/custom/templates/muc-chatarea.js +++ b/conversejs/custom/templates/muc-chatarea.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { api } from '@converse/headless' import tplMUCChatarea from '../../src/plugins/muc-views/templates/muc-chatarea.js' import { html } from 'lit' diff --git a/conversejs/custom/templates/muc-head.js b/conversejs/custom/templates/muc-head.js index ebd1ef7a..ed6849b6 100644 --- a/conversejs/custom/templates/muc-head.js +++ b/conversejs/custom/templates/muc-head.js @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + import { html } from 'lit' import { api } from '@converse/headless' import { until } from 'lit/directives/until.js' diff --git a/conversejs/custom/templates/muc.js b/conversejs/custom/templates/muc.js index d3da4caf..3dfebd51 100644 --- a/conversejs/custom/templates/muc.js +++ b/conversejs/custom/templates/muc.js @@ -4,6 +4,9 @@ // SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + // Must import the original muc.js, because it imports some custom elements files. import '../../src/plugins/muc-views/templates/muc.js' import { getChatRoomBodyTemplate } from '../../src/plugins/muc-views/utils.js' diff --git a/conversejs/lib/auth.ts b/conversejs/lib/auth.ts index bbe1d1ec..b2ffac70 100644 --- a/conversejs/lib/auth.ts +++ b/conversejs/lib/auth.ts @@ -4,7 +4,7 @@ import type { ProsodyAuthentInfos } from 'shared/lib/types' -interface AuthHeader { [key: string]: string } +type AuthHeader = Record async function getLocalAuthentInfos ( authenticationUrl: string, @@ -66,7 +66,7 @@ async function getLocalAuthentInfos ( { 'content-type': 'application/json;charset=UTF-8' } - ) + ) as HeadersInit ) }) @@ -104,7 +104,7 @@ async function getLocalAuthentInfos ( function getLivechatTokenAuthInfos (): ProsodyAuthentInfos | undefined { try { const hash = window.location.hash - if (!hash || !hash.startsWith('#?')) { return undefined } + if (!hash?.startsWith('#?')) { return undefined } // We try to read the hash as a queryString. const u = new URL('http://localhost' + hash.substring(1)) const jid = u.searchParams.get('j') diff --git a/conversejs/lib/plugins/livechat-emojis.ts b/conversejs/lib/plugins/livechat-emojis.ts index b1b8ab42..d108d40b 100644 --- a/conversejs/lib/plugins/livechat-emojis.ts +++ b/conversejs/lib/plugins/livechat-emojis.ts @@ -17,19 +17,19 @@ export const livechatEmojisPlugin = { livechat_custom_emojis_url: false }) - _converse.api.listen.on('loadEmojis', async (_context: Object, json: any) => { - const url = _converse.api.settings.get('livechat_custom_emojis_url') + _converse.api.listen.on('loadEmojis', async (_context: object, json: Record>) => { + const url = _converse.api.settings.get('livechat_custom_emojis_url') as string | undefined if (!url) { return json } - let customs + let customs: CustomEmojiDefinition[] | undefined try { customs = await loadCustomEmojis(url) } catch (err) { console.error(err) } - if (customs === undefined || !customs?.length) { + if (!customs?.length) { return json } @@ -51,7 +51,7 @@ export const livechatEmojisPlugin = { // We must also remove any existing emojis in category other than custom for (const type of Object.keys(json)) { - const v: {[key: string]: any} = json[type] + const v: Record = json[type] if (type !== 'custom' && type !== 'modifiers' && (def.sn in v)) { // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete v[def.sn] diff --git a/conversejs/lib/plugins/livechat-specific/chatroom-message.ts b/conversejs/lib/plugins/livechat-specific/chatroom-message.ts index c34ddff7..0dd5c49f 100644 --- a/conversejs/lib/plugins/livechat-specific/chatroom-message.ts +++ b/conversejs/lib/plugins/livechat-specific/chatroom-message.ts @@ -2,7 +2,8 @@ // // SPDX-License-Identifier: AGPL-3.0-only -export function chatRoomMessageOverrides (): {[key: string]: Function} { +// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type +export function chatRoomMessageOverrides (): Record { return { /* By default, ConverseJS groups messages from the same users for a 10 minutes period. * This make no sense in a livechat room. So we override isFollowup to ignore. */ diff --git a/conversejs/lib/plugins/livechat-specific/chatroom.ts b/conversejs/lib/plugins/livechat-specific/chatroom.ts index 297c0ed4..5a82a8fe 100644 --- a/conversejs/lib/plugins/livechat-specific/chatroom.ts +++ b/conversejs/lib/plugins/livechat-specific/chatroom.ts @@ -2,7 +2,8 @@ // // SPDX-License-Identifier: AGPL-3.0-only -export function chatRoomOverrides (): {[key: string]: Function} { +// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type +export function chatRoomOverrides (): Record { return { getActionInfoMessage: function getActionInfoMessage (this: any, code: string, nick: string, actor: any): any { if (code === '303') { @@ -27,8 +28,9 @@ export function chatRoomOverrides (): {[key: string]: Function} { initOccupants: function initOccupants (this: any) { const r = this.__super__.initOccupants() + // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type const originalComparatorFunction: Function = this.occupants.comparator - this.occupants.comparator = function (this: any, occupant1: any, occupant2: any): Number { + this.occupants.comparator = function (this: any, occupant1: any, occupant2: any): number { // Overriding Occupants comparators, to display anonymous users at the end of the list. const nick1: string = occupant1.getDisplayName() const nick2: string = occupant2.getDisplayName() diff --git a/conversejs/lib/plugins/livechat-specific/message-action.ts b/conversejs/lib/plugins/livechat-specific/message-action.ts index 87bb70ca..15452174 100644 --- a/conversejs/lib/plugins/livechat-specific/message-action.ts +++ b/conversejs/lib/plugins/livechat-specific/message-action.ts @@ -19,7 +19,7 @@ export function customizeMessageAction (plugin: any): void { try { txt += this.model.getDisplayName() as string txt += ' - ' - const date = new Date(this.model.get('edited') || this.model.get('time')) + const date = new Date((this.model.get('edited') || this.model.get('time')) as string) txt += date.toLocaleDateString() + ' ' + date.toLocaleTimeString() txt += '\n' } catch {} diff --git a/conversejs/lib/plugins/livechat-specific/toolbar.ts b/conversejs/lib/plugins/livechat-specific/toolbar.ts index 32c4ce6f..a832fa3d 100644 --- a/conversejs/lib/plugins/livechat-specific/toolbar.ts +++ b/conversejs/lib/plugins/livechat-specific/toolbar.ts @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0-only +// FIXME: @stylistic/indent is buggy with strings literrals. +/* eslint-disable @stylistic/indent */ + /** * Do some customization on the toolbar: * * change the appearance of the toggle occupants button diff --git a/conversejs/lib/plugins/livechat-specific/utils.ts b/conversejs/lib/plugins/livechat-specific/utils.ts index 14644041..b81e3a4c 100644 --- a/conversejs/lib/plugins/livechat-specific/utils.ts +++ b/conversejs/lib/plugins/livechat-specific/utils.ts @@ -25,7 +25,7 @@ export function getOpenPromise (): any { promise.isResolved = false promise.isPending = false promise.isRejected = true - throw (e) + throw (e as Error) } ) return promise diff --git a/conversejs/lib/plugins/livechat-viewer-mode.ts b/conversejs/lib/plugins/livechat-viewer-mode.ts index 4d889c88..b3d2cd7b 100644 --- a/conversejs/lib/plugins/livechat-viewer-mode.ts +++ b/conversejs/lib/plugins/livechat-viewer-mode.ts @@ -22,11 +22,11 @@ export const livechatViewerModePlugin = { console.error('[livechatViewerModePlugin] getDefaultMUCNickname is not initialized.') } else { Object.assign(_converse.exports, { - getDefaultMUCNickname: function (this: any): any { + getDefaultMUCNickname: function (this: any, ...args: any[]): any { if (!_converse.api.settings.get('livechat_enable_viewer_mode')) { - return originalGetDefaultMUCNickname.apply(this, arguments) + return originalGetDefaultMUCNickname.apply(this, args) } - return originalGetDefaultMUCNickname.apply(this, arguments) ?? + return originalGetDefaultMUCNickname.apply(this, args) ?? getPreviousAnonymousNick() ?? randomNick('Anonymous') } @@ -72,8 +72,8 @@ export const livechatViewerModePlugin = { // Note: when previousNickname is set, model.get('nick') has not the nick yet... // It will only come after receiving a presence stanza. // So we use previousNickname before trying to read the model. - const nick = getPreviousAnonymousNick() ?? (model?.get ? model.get('nick') : '') - refreshViewerMode(nick && !/^Anonymous /.test(nick)) + const nick = getPreviousAnonymousNick() ?? (model?.get ? model.get('nick') as string : '') + refreshViewerMode(!!nick && !/^Anonymous /.test(nick)) }) } } diff --git a/conversejs/lib/plugins/slow-mode.ts b/conversejs/lib/plugins/slow-mode.ts index 748a0a25..c03f7984 100644 --- a/conversejs/lib/plugins/slow-mode.ts +++ b/conversejs/lib/plugins/slow-mode.ts @@ -21,7 +21,13 @@ export const slowModePlugin = { return } - const slowModeDuration = parseInt(chatbox?.config?.get('slow_mode_duration')) + const slowModeDurationRaw = chatbox?.config?.get('slow_mode_duration') ?? NaN + const slowModeDuration = + typeof slowModeDurationRaw === 'string' + ? parseInt(slowModeDurationRaw) + : typeof slowModeDurationRaw === 'number' + ? Math.trunc(slowModeDurationRaw) + : NaN if (!(slowModeDuration > 0)) { // undefined, NaN, ... are not considered > 0. return } diff --git a/conversejs/lib/utils.ts b/conversejs/lib/utils.ts index 3893c8de..924c5101 100644 --- a/conversejs/lib/utils.ts +++ b/conversejs/lib/utils.ts @@ -5,7 +5,7 @@ function inIframe (): boolean { try { return window.self !== window.top - } catch (e) { + } catch (_err) { return true } } diff --git a/eslint.config.mjs b/eslint.config.mjs index aae805eb..8d402c76 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -6,6 +6,7 @@ // * lint shared // * lint conversejs // * use eslint-plugin-lit +// * delete old .eslintrc.json files import love from 'eslint-config-love' import eslint from '@eslint/js' @@ -24,8 +25,7 @@ export default tseslint.config( 'support/documentation', 'support', 'build-*js', - 'shared', - 'conversejs' + 'shared' // FIXME ] }, eslint.configs.recommended, @@ -55,7 +55,8 @@ export default tseslint.config( files: ['**/*.ts'], rules: { '@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }], - '@typescript-eslint/no-unused-vars': [2, { argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }], + 'no-unused-vars': ['error', { argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }], + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }], '@typescript-eslint/no-floating-promises': 'error', '@typescript-eslint/no-misused-promises': ['error', { checksVoidReturn: false }], '@typescript-eslint/no-var-requires': 'off', @@ -83,8 +84,45 @@ export default tseslint.config( code: 120, comments: 120 } - ], - 'no-unused-vars': 'off' + ] + } + }, + { + files: ['**/*.js'], + rules: { + // Disabling typescript-eslint rules for JS files (did not find a simplier way...) + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-floating-promises': 'off', + '@typescript-eslint/no-misused-promises': 'off', + '@typescript-eslint/no-var-requires': 'off', + '@typescript-eslint/strict-boolean-expressions': 'off', + '@typescript-eslint/return-await': 'off', + '@typescript-eslint/no-invalid-void-type': 'off', + '@typescript-eslint/triple-slash-reference': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/init-declarations': 'off', + '@typescript-eslint/consistent-type-imports': 'off', + '@typescript-eslint/consistent-type-exports': 'off', + '@typescript-eslint/no-require-imports': 'off', + '@typescript-eslint/unbound-method': 'off', + '@typescript-eslint/prefer-promise-reject-errors': 'off', + '@typescript-eslint/max-params': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/no-confusing-void-expression': 'off', + '@typescript-eslint/class-methods-use-this': 'off', + '@typescript-eslint/non-nullable-type-assertion-style': 'off', + + 'max-params': 'off', + 'init-declarations': 'off', + 'no-unused-vars': ['error', { argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }], + 'max-len': [ + 'error', + { + code: 120, + comments: 120 + } + ] } }, { @@ -108,7 +146,7 @@ export default tseslint.config( } }, { - files: ['shared/**/*.js', 'shared/**/*.ts'], // only ts? + files: ['shared/**/*.js', 'shared/**/*.ts'], languageOptions: { ecmaVersion: 6, globals: { @@ -130,7 +168,7 @@ export default tseslint.config( } }, { - files: ['client/**/*.js', 'client/**/*.ts'], // only ts? + files: ['client/**/*.js', 'client/**/*.ts', 'conversejs/**/*.js', 'conversejs/**/*.ts'], languageOptions: { ecmaVersion: 6, globals: { @@ -139,7 +177,10 @@ export default tseslint.config( parser: typescriptParser, parserOptions: { ecmaVersion: 2018, - project: './client/tsconfig.json' + project: [ + './client/tsconfig.json', + './conversejs/tsconfig.json' + ] } }, // FIXME: not sure elintLit works. @@ -149,5 +190,13 @@ export default tseslint.config( rules: { ...eslintLit.configs['flat/recommended'].rules } + }, + { + files: ['conversejs/build-*.js', 'conversejs/loc.keys.js', 'conversejs/custom/webpack.livechat.js'], + languageOptions: { + globals: { + ...globals.node + } + } } )