eslint 8.57 WIP:

* tweaking some more rules.
* fixing linting.
This commit is contained in:
John Livingston
2024-09-09 20:01:25 +02:00
parent c010758164
commit fd27105c2c
34 changed files with 165 additions and 36 deletions

View File

@ -4,7 +4,7 @@
import type { ProsodyAuthentInfos } from 'shared/lib/types'
interface AuthHeader { [key: string]: string }
type AuthHeader = Record<string, string>
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')

View File

@ -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<string, Record<string, unknown>>) => {
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<string, any> = json[type]
if (type !== 'custom' && type !== 'modifiers' && (def.sn in v)) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete v[def.sn]

View File

@ -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<string, Function> {
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. */

View File

@ -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<string, Function> {
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()

View File

@ -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 {}

View File

@ -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

View File

@ -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

View File

@ -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))
})
}
}

View File

@ -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
}

View File

@ -5,7 +5,7 @@
function inIframe (): boolean {
try {
return window.self !== window.top
} catch (e) {
} catch (_err) {
return true
}
}