From 6957b3e404d59aff40f84f72616deec48499262c Mon Sep 17 00:00:00 2001 From: gnuxie Date: Thu, 21 Mar 2024 20:13:41 +0000 Subject: [PATCH] Fix eslint (i don't think this was ever working :/) --- .eslintrc.js | 6 +- package.json | 3 +- src/appservice/AppService.ts | 12 +-- src/capabilities/CommonRenderers.tsx | 10 +- .../DraupnirRendererMessageCollector.tsx | 8 +- .../StandardUserConsequencesRenderer.tsx | 10 +- src/commands/Ban.tsx | 48 ++++----- src/commands/CommandHandler.ts | 10 +- src/commands/KickCommand.tsx | 16 +-- src/commands/RedactCommand.ts | 44 ++++----- src/commands/StatusCommand.tsx | 2 +- src/commands/Unban.ts | 16 +-- .../interface-manager/DeadDocument.ts | 2 +- .../interface-manager/DeadDocumentMarkdown.ts | 4 +- .../interface-manager/DeadDocumentMatrix.ts | 6 +- src/commands/interface-manager/JSXFactory.ts | 1 + .../MatrixInterfaceAdaptor.ts | 6 +- .../MatrixPromptForAccept.tsx | 2 +- src/protections/BanPropagation.tsx | 32 +++--- src/protections/BasicFlooding.ts | 20 ++-- .../DefaultEnabledProtectionsMigration.ts | 88 ++++++++--------- src/protections/MessageIsVoice.ts | 2 +- src/queues/ProtectedRoomActivityTracker.ts | 4 +- test/integration/abuseReportTest.ts | 12 +-- test/integration/clientHelper.ts | 2 +- .../commands/hijackRoomCommandTest.ts | 2 +- .../integration/commands/redactCommandTest.ts | 4 +- test/integration/commands/roomsTest.ts | 4 +- test/scripts/memberQueryTest.ts | 8 +- yarn.lock | 99 ++++++++++++++++++- 30 files changed, 295 insertions(+), 188 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 92659dad..7da1513e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,4 +1,5 @@ module.exports = { + "extends": [ "plugin:editorconfig/all" ], "env": { "browser": false, "es6": true, @@ -6,11 +7,12 @@ module.exports = { }, "parser": "@typescript-eslint/parser", "parserOptions": { - "project": "tsconfig.json", + "project": ["tsconfig.json", "test/tsconfig.json"], "sourceType": "module" }, "plugins": [ - "@typescript-eslint" + "@typescript-eslint", + "editorconfig" ], "root": true, "rules": { diff --git a/package.json b/package.json index 08f64108..b6f8bee3 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "postbuild": "yarn describe-version", "describe-version": "(git describe > version.txt.tmp && mv version.txt.tmp version.txt) || true && rm -f version.txt.tmp", "remove-tests-from-lib": "rm -rf lib/test/ && cp -r lib/src/* lib/ && rm -rf lib/src/", - "lint": "eslint ./**/*.ts", + "lint": "eslint -c .eslintrc.js src/**/*.ts test/**/*.ts src/**/*.tsx", "start:dev": "yarn build && node --async-stack-traces lib/index.js", "test": "ts-mocha --project ./tsconfig.json test/commands/**/*.ts", "test:integration": "NODE_ENV=harness ts-mocha --async-stack-traces --forbid-only --require test/integration/fixtures.ts --timeout 300000 --project ./tsconfig.json \"test/integration/**/*Test.ts\"", @@ -40,6 +40,7 @@ "@typescript-eslint/parser": "^6.19.0", "crypto-js": "^4.2.0", "eslint": "^8.56", + "eslint-plugin-editorconfig": "^4.0.3", "expect": "^29.7.0", "mocha": "^10.2.0", "ts-mocha": "^10.0.0", diff --git a/src/appservice/AppService.ts b/src/appservice/AppService.ts index 74ed1054..98cadfa2 100644 --- a/src/appservice/AppService.ts +++ b/src/appservice/AppService.ts @@ -242,12 +242,12 @@ export class MjolnirAppService { this.commands.handleEvent(mxEvent); const decodeResult = this.eventDecoder.decodeEvent(mxEvent); if (isError(decodeResult)) { - log.error( - `Got an error when decoding an event for the appservice`, - decodeResult.error.uuid, - decodeResult.error - ); - return; + log.error( + `Got an error when decoding an event for the appservice`, + decodeResult.error.uuid, + decodeResult.error + ); + return; } const roomID = decodeResult.ok.room_id; this.roomStateManagerFactory.handleTimelineEvent(roomID, decodeResult.ok); diff --git a/src/capabilities/CommonRenderers.tsx b/src/capabilities/CommonRenderers.tsx index 53fc31b7..76d6634e 100644 --- a/src/capabilities/CommonRenderers.tsx +++ b/src/capabilities/CommonRenderers.tsx @@ -15,9 +15,9 @@ import { renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer export function renderElaborationTrail(error: ActionError): DocumentNode { return
Elaboration trail - +
} @@ -82,7 +82,7 @@ export function renderRoomSetResult(roomResults: RoomSetResult, { summary }: { s return
{summary} + return
  • {renderRoomOutcome(roomID, outcome)}
  • + })}
    } diff --git a/src/capabilities/DraupnirRendererMessageCollector.tsx b/src/capabilities/DraupnirRendererMessageCollector.tsx index 9a47cabe..30c4d8c6 100644 --- a/src/capabilities/DraupnirRendererMessageCollector.tsx +++ b/src/capabilities/DraupnirRendererMessageCollector.tsx @@ -19,10 +19,10 @@ export class DraupnirRendererMessageCollector implements RendererMessageCollecto private sendMessage(document: DocumentNode): void { Task((async () => { await renderMatrixAndSend( - {document}, - this.managementRoomID, - undefined, - this.client, + {document}, + this.managementRoomID, + undefined, + this.client, ) })()); } diff --git a/src/capabilities/StandardUserConsequencesRenderer.tsx b/src/capabilities/StandardUserConsequencesRenderer.tsx index 0b171d2b..c1e62e4e 100644 --- a/src/capabilities/StandardUserConsequencesRenderer.tsx +++ b/src/capabilities/StandardUserConsequencesRenderer.tsx @@ -26,11 +26,11 @@ function renderResultForUserInSetMap(usersInSetMap: ResultForUserInSetMap, { description: DescriptionMeta, }): DocumentNode { return
    - {description.name}: {ingword} {usersInSetMap.size} {usersInSetMap.size === 1 ? 'user' : 'users'} from protected rooms. - {[...usersInSetMap.entries()].map(([userID, roomResults]) => { - return renderRoomSetResult(roomResults, { summary: {userID} will be {nnedword} from {roomResults.map.size} rooms. }) - })} -
    + {description.name}: {ingword} {usersInSetMap.size} {usersInSetMap.size === 1 ? 'user' : 'users'} from protected rooms. + {[...usersInSetMap.entries()].map(([userID, roomResults]) => { + return renderRoomSetResult(roomResults, { summary: {userID} will be {nnedword} from {roomResults.map.size} rooms. }) + })} + } diff --git a/src/commands/Ban.tsx b/src/commands/Ban.tsx index efa70a8b..673206b2 100644 --- a/src/commands/Ban.tsx +++ b/src/commands/Ban.tsx @@ -51,31 +51,31 @@ async function ban( entity: UserID|MatrixRoomReference|string, policyRoomReference: MatrixRoomReference, ...reasonParts: string[] - ): Promise> { - const policyListEditorResult = await findPolicyRoomEditorFromRoomReference( - this.draupnir, - policyRoomReference - ); - if (isError(policyListEditorResult)) { - return policyListEditorResult; - } - const policyListEditor = policyListEditorResult.ok; - const reason = reasonParts.join(' '); - if (entity instanceof UserID) { - return await policyListEditor.banEntity(PolicyRuleType.User, entity.toString(), reason); - } else if (typeof entity === 'string') { - return await policyListEditor.banEntity(PolicyRuleType.Server,entity, reason); - } else { - const resolvedRoomReference = await resolveRoomReferenceSafe( - this.draupnir.client, - entity - ); - if (isError(resolvedRoomReference)) { - return resolvedRoomReference; - } - return await policyListEditor.banEntity(PolicyRuleType.Server, resolvedRoomReference.ok.toRoomIDOrAlias(), reason); - } +): Promise> { + const policyListEditorResult = await findPolicyRoomEditorFromRoomReference( + this.draupnir, + policyRoomReference + ); + if (isError(policyListEditorResult)) { + return policyListEditorResult; } + const policyListEditor = policyListEditorResult.ok; + const reason = reasonParts.join(' '); + if (entity instanceof UserID) { + return await policyListEditor.banEntity(PolicyRuleType.User, entity.toString(), reason); + } else if (typeof entity === 'string') { + return await policyListEditor.banEntity(PolicyRuleType.Server,entity, reason); + } else { + const resolvedRoomReference = await resolveRoomReferenceSafe( + this.draupnir.client, + entity + ); + if (isError(resolvedRoomReference)) { + return resolvedRoomReference; + } + return await policyListEditor.banEntity(PolicyRuleType.Server, resolvedRoomReference.ok.toRoomIDOrAlias(), reason); + } +} defineInterfaceCommand({ designator: ["ban"], diff --git a/src/commands/CommandHandler.ts b/src/commands/CommandHandler.ts index 4dbe2d45..34c1c815 100644 --- a/src/commands/CommandHandler.ts +++ b/src/commands/CommandHandler.ts @@ -103,17 +103,17 @@ export async function handleCommand( export function extractCommandFromMessageBody( body: string, { prefix, - localpart, - userId, - additionalPrefixes, - allowNoPrefix + localpart, + userId, + additionalPrefixes, + allowNoPrefix }: { prefix: string, localpart: string, userId: string, additionalPrefixes: string[], allowNoPrefix: boolean -}): string | undefined { + }): string | undefined { const plainPrefixes = [prefix, localpart, userId, ...additionalPrefixes]; const allPossiblePrefixes = [ ...plainPrefixes.map(p => `!${p}`), diff --git a/src/commands/KickCommand.tsx b/src/commands/KickCommand.tsx index 4572a95b..d23eeef9 100644 --- a/src/commands/KickCommand.tsx +++ b/src/commands/KickCommand.tsx @@ -51,14 +51,14 @@ function renderUsersToKick(usersToKick: UsersToKick): DocumentNode { Kicking {usersToKick.size} unique users from protected rooms. - {[...usersToKick.entries()].map(([userID, rooms]) => { -
    - Kicking {userID} from {rooms.length} rooms. -
      - {rooms.map(room =>
    • {room}
    • )} -
    -
    - })} + {[...usersToKick.entries()].map(([userID, rooms]) => { +
    + Kicking {userID} from {rooms.length} rooms. +
      + {rooms.map(room =>
    • {room}
    • )} +
    +
    + })} } diff --git a/src/commands/RedactCommand.ts b/src/commands/RedactCommand.ts index 31c286c7..63670c29 100644 --- a/src/commands/RedactCommand.ts +++ b/src/commands/RedactCommand.ts @@ -88,29 +88,29 @@ defineInterfaceCommand({ findPresentationType("MatrixEventReference") ), }], - new RestDescription( - "reason", - findPresentationType("string"), - async function(_parameter) { - return { - suggestions: this.draupnir.config.commands.ban.defaultReasons - } + new RestDescription( + "reason", + findPresentationType("string"), + async function(_parameter) { + return { + suggestions: this.draupnir.config.commands.ban.defaultReasons } - ), - new KeywordsDescription({ - limit: { - name: "limit", - isFlag: false, - acceptor: findPresentationType("string"), - description: 'Limit the number of messages to be redacted per room.' - }, - room: { - name: 'room', - isFlag: false, - acceptor: findPresentationType("MatrixRoomReference"), - description: 'Allows the command to be scoped to just one protected room.' - } - }), + } + ), + new KeywordsDescription({ + limit: { + name: "limit", + isFlag: false, + acceptor: findPresentationType("string"), + description: 'Limit the number of messages to be redacted per room.' + }, + room: { + name: 'room', + isFlag: false, + acceptor: findPresentationType("MatrixRoomReference"), + description: 'Allows the command to be scoped to just one protected room.' + } + }), ), command: redactCommand, summary: "Redacts either a users's recent messagaes within protected rooms or a specific message shared with the bot." diff --git a/src/commands/StatusCommand.tsx b/src/commands/StatusCommand.tsx index b27935bd..e3d8d398 100644 --- a/src/commands/StatusCommand.tsx +++ b/src/commands/StatusCommand.tsx @@ -41,7 +41,7 @@ defineInterfaceCommand({ table: "mjolnir", parameters: parameters([]), command: async function (this: DraupnirContext): Promise> { - return Ok(await draupnirStatusInfo(this.draupnir)) + return Ok(await draupnirStatusInfo(this.draupnir)) }, summary: "Show the status of the bot." }) diff --git a/src/commands/Unban.ts b/src/commands/Unban.ts index 2b932104..13f7b187 100644 --- a/src/commands/Unban.ts +++ b/src/commands/Unban.ts @@ -73,14 +73,14 @@ async function unban( const policyRoomUnban = entity instanceof UserID ? await policyRoomEditor.ok.unbanEntity(PolicyRuleType.User, entity.toString()) : typeof entity === 'string' - ? await policyRoomEditor.ok.unbanEntity(PolicyRuleType.Server, entity) - : await (async () => { - const bannedRoom = await resolveRoomReferenceSafe(this.client, entity); - if (isError(bannedRoom)) { - return bannedRoom; - } - return await policyRoomEditor.ok.unbanEntity(PolicyRuleType.Room, bannedRoom.ok.toRoomIDOrAlias()); - })(); + ? await policyRoomEditor.ok.unbanEntity(PolicyRuleType.Server, entity) + : await (async () => { + const bannedRoom = await resolveRoomReferenceSafe(this.client, entity); + if (isError(bannedRoom)) { + return bannedRoom; + } + return await policyRoomEditor.ok.unbanEntity(PolicyRuleType.Room, bannedRoom.ok.toRoomIDOrAlias()); + })(); if (isError(policyRoomUnban)) { return policyRoomUnban; } diff --git a/src/commands/interface-manager/DeadDocument.ts b/src/commands/interface-manager/DeadDocument.ts index adb5e1f4..15cfb134 100644 --- a/src/commands/interface-manager/DeadDocument.ts +++ b/src/commands/interface-manager/DeadDocument.ts @@ -327,7 +327,7 @@ export class FringeWalker { throw new TypeError("Leaf nodes should not be marked as an inner node"); } this.renderer.getLeafRenderer(annotatedNode.node.tag) - (annotatedNode.node.tag, annotatedNode.node as unknown as LeafNode, this.context); + (annotatedNode.node.tag, annotatedNode.node as unknown as LeafNode, this.context); break; default: throw new TypeError(`Uknown fringe type ${annotatedNode.type}`); diff --git a/src/commands/interface-manager/DeadDocumentMarkdown.ts b/src/commands/interface-manager/DeadDocumentMarkdown.ts index 5c84d88c..1a37c0c4 100644 --- a/src/commands/interface-manager/DeadDocumentMarkdown.ts +++ b/src/commands/interface-manager/DeadDocumentMarkdown.ts @@ -55,7 +55,9 @@ MARKDOWN_RENDERER.registerRenderer { diff --git a/src/commands/interface-manager/JSXFactory.ts b/src/commands/interface-manager/JSXFactory.ts index 63553ac5..40f2ce04 100644 --- a/src/commands/interface-manager/JSXFactory.ts +++ b/src/commands/interface-manager/JSXFactory.ts @@ -45,6 +45,7 @@ export function JSXFactory(tag: NodeTag, properties: unknown, ...rawChildren: (D } +// eslint-disable-next-line no-redeclare namespace JSXFactory { export interface IntrinsicElements { [elemName: string]: any; diff --git a/src/commands/interface-manager/MatrixInterfaceAdaptor.ts b/src/commands/interface-manager/MatrixInterfaceAdaptor.ts index 8cb786fd..0e6debfe 100644 --- a/src/commands/interface-manager/MatrixInterfaceAdaptor.ts +++ b/src/commands/interface-manager/MatrixInterfaceAdaptor.ts @@ -148,9 +148,9 @@ export function findMatrixInterfaceAdaptor(interfaceCommand: InterfaceCommand Promise>(details: { - interfaceCommand: InterfaceCommand, - renderer: RendererSignature - }) { + interfaceCommand: InterfaceCommand, + renderer: RendererSignature +}) { internMatrixInterfaceAdaptor( details.interfaceCommand, new MatrixInterfaceAdaptor( diff --git a/src/commands/interface-manager/MatrixPromptForAccept.tsx b/src/commands/interface-manager/MatrixPromptForAccept.tsx index 87abdc33..e3f2785d 100644 --- a/src/commands/interface-manager/MatrixPromptForAccept.tsx +++ b/src/commands/interface-manager/MatrixPromptForAccept.tsx @@ -30,7 +30,7 @@ type DefaultPromptContext = StaticDecode; const DefaultPromptContext = Type.Composite([ PromptContext, Type.Object({ - default: Type.String(), + default: Type.String(), }) ]); diff --git a/src/protections/BanPropagation.tsx b/src/protections/BanPropagation.tsx index 675b9ee4..598012e5 100644 --- a/src/protections/BanPropagation.tsx +++ b/src/protections/BanPropagation.tsx @@ -78,9 +78,9 @@ async function promptBanPropagation( The user {renderMentionPill(change.userID, change.content.displayname ?? change.userID)} was banned in {change.roomID} by {new UserID(change.sender)} for {change.content.reason ?? ''}.
    Would you like to add the ban to a policy list? -
      - {editablePolicyRoomIDs.map((room) =>
    1. {room.toRoomIDOrAlias()}
    2. )} -
    +
      + {editablePolicyRoomIDs.map((room) =>
    1. {room.toRoomIDOrAlias()}
    2. )} +
    , draupnir.managementRoomID, undefined, @@ -111,9 +111,9 @@ async function promptUnbanPropagation( from the room {renderRoomPill(MatrixRoomReference.fromRoomID(roomID))} by {membershipChange.sender} for {membershipChange.content.reason ?? ''}.
    However there are rules in Draupnir's watched lists matching this user:
      - { - rulesMatchingUser.map(match =>
    • {renderListRules(match)}
    • ) - } + { + rulesMatchingUser.map(match =>
    • {renderListRules(match)}
    • ) + }
    Would you like to remove these rules and unban the user from all protected rooms? , @@ -152,7 +152,7 @@ export class BanPropagationProtection capabilities: BanPropagationProtectionCapabilities, protectedRoomsSet: ProtectedRoomsSet, private readonly draupnir: Draupnir, - ) { + ) { super(description, capabilities, protectedRoomsSet, [], []); this.userConsequences = capabilities.userConsequences; // FIXME: These listeners are gonna leak all over if we don't have a @@ -301,12 +301,12 @@ describeProtection({ userConsequences: 'StandardUserConsequences', }, factory: (decription, protectedRoomsSet, draupnir, capabilities, _settings) => - Ok( - new BanPropagationProtection( - decription, - capabilities, - protectedRoomsSet, - draupnir - ) - ), - }); + Ok( + new BanPropagationProtection( + decription, + capabilities, + protectedRoomsSet, + draupnir + ) + ), +}); diff --git a/src/protections/BasicFlooding.ts b/src/protections/BasicFlooding.ts index fd4c58f6..686e71e3 100644 --- a/src/protections/BasicFlooding.ts +++ b/src/protections/BasicFlooding.ts @@ -68,22 +68,22 @@ describeProtection({ maxPerMinute: new SafeIntegerProtectionSetting( 'maxPerMinute' )}, - { - maxPerMinute: DEFAULT_MAX_PER_MINUTE - }) - }); + { + maxPerMinute: DEFAULT_MAX_PER_MINUTE + }) +}); export class BasicFloodingProtection extends AbstractProtection implements DraupnirProtection { diff --git a/src/protections/DefaultEnabledProtectionsMigration.ts b/src/protections/DefaultEnabledProtectionsMigration.ts index c8a9ee09..d3ea6114 100644 --- a/src/protections/DefaultEnabledProtectionsMigration.ts +++ b/src/protections/DefaultEnabledProtectionsMigration.ts @@ -6,50 +6,50 @@ import { ActionError,ActionException,ActionExceptionKind,DRAUPNIR_SCHEMA_VERSION_KEY, MjolnirEnabledProtectionsEvent, MjolnirEnabledProtectionsEventType, Ok, SchemedDataManager, Value, findProtection } from "matrix-protection-suite"; export const DefaultEnabledProtectionsMigration = new SchemedDataManager([ - async function enableBanPropagationByDefault(input) { - if (!Value.Check(MjolnirEnabledProtectionsEvent, input)) { - return ActionError.Result( - `The data for ${MjolnirEnabledProtectionsEventType} is corrupted.` - ); - } - const banPropagationProtection = findProtection('BanPropagationProtection'); - if (banPropagationProtection === undefined) { - const message = `Cannot find the BanPropagationProtection`; - return ActionException.Result(message, { - exception: new TypeError(message), - exceptionKind: ActionExceptionKind.Unknown, - }) - } - const enabled = new Set(input.enabled); - enabled.add(banPropagationProtection.name); - return Ok({ - enabled: [...enabled], - [DRAUPNIR_SCHEMA_VERSION_KEY]: 1, - }); - }, - async function enableMemberAndServerSynchronisationByDefault(input) { - if (!Value.Check(MjolnirEnabledProtectionsEvent, input)) { - return ActionError.Result( - `The data for ${MjolnirEnabledProtectionsEventType} is corrupted.` - ); - } - const enabledProtections = new Set(input.enabled); - // we go through the process of finding them just so we can be sure that we spell their names correctly. - const memberBanSynchronisationProtection = findProtection('MemberBanSynchronisationProtection'); - const serverBanSynchronisationProtection = findProtection('ServerBanSynchronisationProtection'); - if (memberBanSynchronisationProtection === undefined || serverBanSynchronisationProtection === undefined) { - const message = `Cannot find the member ban or server ban synchronisation protections`; - return ActionException.Result(message, { - exception: new TypeError(message), - exceptionKind: ActionExceptionKind.Unknown + async function enableBanPropagationByDefault(input) { + if (!Value.Check(MjolnirEnabledProtectionsEvent, input)) { + return ActionError.Result( + `The data for ${MjolnirEnabledProtectionsEventType} is corrupted.` + ); + } + const banPropagationProtection = findProtection('BanPropagationProtection'); + if (banPropagationProtection === undefined) { + const message = `Cannot find the BanPropagationProtection`; + return ActionException.Result(message, { + exception: new TypeError(message), + exceptionKind: ActionExceptionKind.Unknown, + }) + } + const enabled = new Set(input.enabled); + enabled.add(banPropagationProtection.name); + return Ok({ + enabled: [...enabled], + [DRAUPNIR_SCHEMA_VERSION_KEY]: 1, + }); + }, + async function enableMemberAndServerSynchronisationByDefault(input) { + if (!Value.Check(MjolnirEnabledProtectionsEvent, input)) { + return ActionError.Result( + `The data for ${MjolnirEnabledProtectionsEventType} is corrupted.` + ); + } + const enabledProtections = new Set(input.enabled); + // we go through the process of finding them just so we can be sure that we spell their names correctly. + const memberBanSynchronisationProtection = findProtection('MemberBanSynchronisationProtection'); + const serverBanSynchronisationProtection = findProtection('ServerBanSynchronisationProtection'); + if (memberBanSynchronisationProtection === undefined || serverBanSynchronisationProtection === undefined) { + const message = `Cannot find the member ban or server ban synchronisation protections`; + return ActionException.Result(message, { + exception: new TypeError(message), + exceptionKind: ActionExceptionKind.Unknown + }); + } + for (const protection of [memberBanSynchronisationProtection, serverBanSynchronisationProtection]) { + enabledProtections.add(protection.name); + } + return Ok({ + enabled: [...enabledProtections], + [DRAUPNIR_SCHEMA_VERSION_KEY]: 2, }); } - for (const protection of [memberBanSynchronisationProtection, serverBanSynchronisationProtection]) { - enabledProtections.add(protection.name); - } - return Ok({ - enabled: [...enabledProtections], - [DRAUPNIR_SCHEMA_VERSION_KEY]: 2, - }); - } ]); diff --git a/src/protections/MessageIsVoice.ts b/src/protections/MessageIsVoice.ts index 5dc2293d..f5560042 100644 --- a/src/protections/MessageIsVoice.ts +++ b/src/protections/MessageIsVoice.ts @@ -46,7 +46,7 @@ describeProtection({ }, factory: function(description, protectedRoomsSet, draupnir, capabilities, _settings) { return Ok( - new MessageIsVoiceProtection( + new MessageIsVoiceProtection( description, capabilities, protectedRoomsSet, diff --git a/src/queues/ProtectedRoomActivityTracker.ts b/src/queues/ProtectedRoomActivityTracker.ts index afc931bf..8729fe8e 100644 --- a/src/queues/ProtectedRoomActivityTracker.ts +++ b/src/queues/ProtectedRoomActivityTracker.ts @@ -80,8 +80,8 @@ export class ProtectedRoomActivityTracker { public protectedRoomsByActivity(): string[] { if (!this.activeRoomsCache) { this.activeRoomsCache = [...this.protectedRoomActivities] - .sort((a, b) => b[1] - a[1]) - .map(pair => pair[0]); + .sort((a, b) => b[1] - a[1]) + .map(pair => pair[0]); } return this.activeRoomsCache; } diff --git a/test/integration/abuseReportTest.ts b/test/integration/abuseReportTest.ts index 9d2d8b57..3121af21 100644 --- a/test/integration/abuseReportTest.ts +++ b/test/integration/abuseReportTest.ts @@ -151,7 +151,7 @@ describe("Test: Reporting abuse", async () => { for (let toFind of reportsToFind) { for (let event of notices) { if ("content" in event && "body" in event.content) { - if (!(ABUSE_REPORT_KEY in event.content) || event.content[ABUSE_REPORT_KEY].event_id != toFind.eventId) { + if (!(ABUSE_REPORT_KEY in event.content) || event.content[ABUSE_REPORT_KEY].event_id !== toFind.eventId) { // Not a report or not our report. continue; } @@ -285,7 +285,7 @@ describe("Test: Reporting abuse", async () => { let noticeId; for (let event of notices) { if ("content" in event && ABUSE_REPORT_KEY in event.content) { - if (!(ABUSE_REPORT_KEY in event.content) || event.content[ABUSE_REPORT_KEY].event_id != badEventId) { + if (!(ABUSE_REPORT_KEY in event.content) || event.content[ABUSE_REPORT_KEY].event_id !== badEventId) { // Not a report or not our report. continue; } @@ -298,13 +298,13 @@ describe("Test: Reporting abuse", async () => { // Find the buttons. let buttons: any[] = []; for (let event of notices) { - if (event["type"] != "m.reaction") { + if (event["type"] !== "m.reaction") { continue; } - if (event["content"]["m.relates_to"]["rel_type"] != "m.annotation") { + if (event["content"]["m.relates_to"]["rel_type"] !== "m.annotation") { continue; } - if (event["content"]["m.relates_to"]["event_id"] != noticeId) { + if (event["content"]["m.relates_to"]["event_id"] !== noticeId) { continue; } buttons.push(event); @@ -335,7 +335,7 @@ describe("Test: Reporting abuse", async () => { console.debug("Not confirm"); continue; } - if (!event["content"]["m.relates_to"]["event_id"] == redactButtonId) { + if (!event["content"]["m.relates_to"]["event_id"] === redactButtonId) { console.debug("Not reaction to redact button"); continue; } diff --git a/test/integration/clientHelper.ts b/test/integration/clientHelper.ts index ce9fe5c1..606fd954 100644 --- a/test/integration/clientHelper.ts +++ b/test/integration/clientHelper.ts @@ -183,6 +183,6 @@ export function noticeListener(targetRoomdId: string, cb: (event: any) => void) return (roomId: string, event: any) => { if (roomId !== targetRoomdId) return; if (event?.content?.msgtype !== "m.notice") return; - cb(event); + cb(event); } } diff --git a/test/integration/commands/hijackRoomCommandTest.ts b/test/integration/commands/hijackRoomCommandTest.ts index 2fe39372..87f5eda0 100644 --- a/test/integration/commands/hijackRoomCommandTest.ts +++ b/test/integration/commands/hijackRoomCommandTest.ts @@ -1,4 +1,4 @@ -import { strict as assert } from "assert"; +import { strict as assert } from "assert"; import { newTestUser } from "../clientHelper"; import { getFirstReaction } from "./commandUtils"; import { DraupnirTestContext, draupnirClient } from "../mjolnirSetupUtils"; diff --git a/test/integration/commands/redactCommandTest.ts b/test/integration/commands/redactCommandTest.ts index 0961340a..cb151913 100644 --- a/test/integration/commands/redactCommandTest.ts +++ b/test/integration/commands/redactCommandTest.ts @@ -12,7 +12,9 @@ interface RedactionTestContext extends DraupnirTestContext { describe("Test: The redaction command", function () { // If a test has a timeout while awaitng on a promise then we never get given control back. - afterEach(function() { this.moderator?.stop(); }); + afterEach(function() { + this.moderator?.stop(); + }); it('Mjölnir redacts all of the events sent by a spammer when instructed to by giving their id and a room id.', async function(this: RedactionTestContext) { this.timeout(60000); diff --git a/test/integration/commands/roomsTest.ts b/test/integration/commands/roomsTest.ts index aadf2ae7..a1cbf553 100644 --- a/test/integration/commands/roomsTest.ts +++ b/test/integration/commands/roomsTest.ts @@ -10,7 +10,9 @@ interface RoomsTestContext extends DraupnirTestContext { describe("Test: The rooms commands", function () { // If a test has a timeout while awaitng on a promise then we never get given control back. - afterEach(function() { this.moderator?.stop(); }); + afterEach(function() { + this.moderator?.stop(); + }); it('Mjolnir can protect a room, show that it is protected and then stop protecting the room.', async function(this: RoomsTestContext) { // Create a few users and a room. diff --git a/test/scripts/memberQueryTest.ts b/test/scripts/memberQueryTest.ts index 6b2818d6..6bf70a69 100644 --- a/test/scripts/memberQueryTest.ts +++ b/test/scripts/memberQueryTest.ts @@ -85,10 +85,10 @@ function calculateMedian (arr: number[]): number | undefined { } for (const method of [MemberFetchMethod.JoinedMembers, MemberFetchMethod.Members, MemberFetchMethod.State]) { - const times = getTimes(method)!; - const sum = times.reduce((a, b) => a + b, 0); - const mean = (sum / times.length) || 0; - const median = calculateMedian(times); + const nextTimes = getTimes(method)!; + const sum = nextTimes.reduce((a, b) => a + b, 0); + const mean = (sum / nextTimes.length) || 0; + const median = calculateMedian(nextTimes); console.log(`${method}: total time elapsed ${sum / 1000}seconds, mean time ${mean}ms, median time ${median}ms`); } })(); diff --git a/yarn.lock b/yarn.lock index 4da22270..d52faa31 100644 --- a/yarn.lock +++ b/yarn.lock @@ -79,7 +79,12 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.56.0.tgz#ef20350fec605a7f7035a01764731b2de0f3782b" integrity sha512-gMsVel9D7f2HLkBma9VbtzZRehRogVRfbr++f06nL2vnCGCNlzOD+/MUov/F4p8myyAHspEhVobgjpX64q5m6A== -"@humanwhocodes/config-array@^0.11.13": +"@eslint/js@8.57.0": + version "8.57.0" + resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f" + integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g== + +"@humanwhocodes/config-array@^0.11.13", "@humanwhocodes/config-array@^0.11.14": version "0.11.14" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b" integrity sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg== @@ -153,6 +158,11 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" +"@one-ini/wasm@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@one-ini/wasm/-/wasm-0.1.1.tgz#6013659736c9dbfccc96e8a9c2b3de317df39323" + integrity sha512-XuySG1E38YScSJoMlqovLru4KTUNSjgVTIjyh7qMX6aNN5HY5Ct5LhRJdxO79JtTzKfzV/bnWpz+zquYrISsvw== + "@selderee/plugin-htmlparser2@^0.6.0": version "0.6.0" resolved "https://registry.npmjs.org/@selderee/plugin-htmlparser2/-/plugin-htmlparser2-0.6.0.tgz" @@ -918,6 +928,11 @@ combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6: dependencies: delayed-stream "~1.0.0" +commander@^10.0.0: + version "10.0.1" + resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06" + integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug== + commander@^2.19.0: version "2.20.3" resolved "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz" @@ -1164,6 +1179,16 @@ editorconfig@^0.15.0: semver "^5.6.0" sigmund "^1.0.1" +editorconfig@^1.0.2: + version "1.0.4" + resolved "https://registry.yarnpkg.com/editorconfig/-/editorconfig-1.0.4.tgz#040c9a8e9a6c5288388b87c2db07028aa89f53a3" + integrity sha512-L9Qe08KWTlqYMVvMcTIvMAdl1cDUubzRNYL+WfA4bLDMHe4nemKkpmYzkznE1FwLKu0EEmy6obgQKzMJrg4x9Q== + dependencies: + "@one-ini/wasm" "0.1.1" + commander "^10.0.0" + minimatch "9.0.1" + semver "^7.5.3" + ee-first@1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz" @@ -1219,6 +1244,15 @@ escape-string-regexp@^2.0.0: resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz" integrity sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w== +eslint-plugin-editorconfig@^4.0.3: + version "4.0.3" + resolved "https://registry.yarnpkg.com/eslint-plugin-editorconfig/-/eslint-plugin-editorconfig-4.0.3.tgz#d0ab6179f16cc487eeacb4c9f54cf867b2841d6e" + integrity sha512-5YeDxm6mlv75DrTbRBK9Jw2ogqhjiz8ZCvv9bkuz/MXq0603q9FpQvQlamtas4bX1Gji4YcksY7dq7stPeGaLQ== + dependencies: + editorconfig "^1.0.2" + eslint "^8.40.0" + klona "^2.0.4" + eslint-scope@^7.2.2: version "7.2.2" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-7.2.2.tgz#deb4f92563390f32006894af62a22dba1c46423f" @@ -1232,6 +1266,50 @@ eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4 resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800" integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag== +eslint@^8.40.0: + version "8.57.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.57.0.tgz#c786a6fd0e0b68941aaf624596fb987089195668" + integrity sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ== + dependencies: + "@eslint-community/eslint-utils" "^4.2.0" + "@eslint-community/regexpp" "^4.6.1" + "@eslint/eslintrc" "^2.1.4" + "@eslint/js" "8.57.0" + "@humanwhocodes/config-array" "^0.11.14" + "@humanwhocodes/module-importer" "^1.0.1" + "@nodelib/fs.walk" "^1.2.8" + "@ungap/structured-clone" "^1.2.0" + ajv "^6.12.4" + chalk "^4.0.0" + cross-spawn "^7.0.2" + debug "^4.3.2" + doctrine "^3.0.0" + escape-string-regexp "^4.0.0" + eslint-scope "^7.2.2" + eslint-visitor-keys "^3.4.3" + espree "^9.6.1" + esquery "^1.4.2" + esutils "^2.0.2" + fast-deep-equal "^3.1.3" + file-entry-cache "^6.0.1" + find-up "^5.0.0" + glob-parent "^6.0.2" + globals "^13.19.0" + graphemer "^1.4.0" + ignore "^5.2.0" + imurmurhash "^0.1.4" + is-glob "^4.0.0" + is-path-inside "^3.0.3" + js-yaml "^4.1.0" + json-stable-stringify-without-jsonify "^1.0.1" + levn "^0.4.1" + lodash.merge "^4.6.2" + minimatch "^3.1.2" + natural-compare "^1.4.0" + optionator "^0.9.3" + strip-ansi "^6.0.1" + text-table "^0.2.0" + eslint@^8.56: version "8.56.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.56.0.tgz#4957ce8da409dc0809f99ab07a1b94832ab74b15" @@ -2151,6 +2229,11 @@ jsprim@^1.2.2: json-schema "0.4.0" verror "1.10.0" +klona@^2.0.4: + version "2.0.6" + resolved "https://registry.yarnpkg.com/klona/-/klona-2.0.6.tgz#85bffbf819c03b2f53270412420a4555ef882e22" + integrity sha512-dhG34DXATL5hSxJbIexCft8FChFXtmskoZYnoPWjXQuebWYCNkVeV3KkGegCK9CP1oswI/vQibS2GY7Em/sJJA== + kuler@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz" @@ -2392,6 +2475,13 @@ minimatch@5.0.1: dependencies: brace-expansion "^2.0.1" +minimatch@9.0.1: + version "9.0.1" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.1.tgz#8a555f541cf976c622daf078bb28f29fb927c253" + integrity sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w== + dependencies: + brace-expansion "^2.0.1" + minimatch@9.0.3: version "9.0.3" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.3.tgz#a6e00c3de44c3a542bfaae70abfc22420a6da825" @@ -3109,6 +3199,13 @@ semver@^5.6.0: resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8" integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g== +semver@^7.5.3: + version "7.6.0" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d" + integrity sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg== + dependencies: + lru-cache "^6.0.0" + semver@^7.5.4: version "7.5.4" resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"