From fbb741ab10ea8d81de2ba013244a13083f39f6f6 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 27 May 2021 17:36:44 +0100 Subject: [PATCH 1/6] Switch to new Babel linting config --- .eslintrc.js | 2 +- yarn.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f8514a305..c0c6be63a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,7 +2,7 @@ module.exports = { plugins: [ "matrix-org", ], - extends: ["plugin:matrix-org/javascript"], + extends: ["plugin:matrix-org/babel"], env: { browser: true, node: true, diff --git a/yarn.lock b/yarn.lock index f48a13d6b..0153955a5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2845,8 +2845,8 @@ eslint-config-google@^0.14.0: integrity sha512-WsbX4WbjuMvTdeVL6+J3rK1RGhCTqjsFjX7UMSMgZiyxxaNLkoJENbrGExzERFeoTpGw3F3FypTiWAP9ZXzkEw== "eslint-plugin-matrix-org@github:matrix-org/eslint-plugin-matrix-org#main": - version "0.2.0" - resolved "https://codeload.github.com/matrix-org/eslint-plugin-matrix-org/tar.gz/0ae103fe9af97655be6039fc1e7ad6ea95da310b" + version "0.3.1" + resolved "https://codeload.github.com/matrix-org/eslint-plugin-matrix-org/tar.gz/b55649a0f48ee27155c1968ed5050b6ddc5afdbe" eslint-rule-composer@^0.3.0: version "0.3.0" From b0e2a38325060ea492decbd54366080ebf3bed71 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 27 May 2021 17:50:16 +0100 Subject: [PATCH 2/6] Auto-fix lint errors --- spec/integ/matrix-client-crypto.spec.js | 38 +++++++++------------ src/crypto/OutgoingRoomKeyRequestManager.js | 2 +- src/models/room.js | 33 +++++++----------- src/models/search-result.js | 2 +- src/store/memory.js | 2 +- 5 files changed, 32 insertions(+), 45 deletions(-) diff --git a/spec/integ/matrix-client-crypto.spec.js b/spec/integ/matrix-client-crypto.spec.js index c86e0e60e..cfe85678b 100644 --- a/spec/integ/matrix-client-crypto.spec.js +++ b/spec/integ/matrix-client-crypto.spec.js @@ -28,10 +28,10 @@ limitations under the License. // load olm before the sdk if possible import '../olm-loader'; -import {logger} from '../../src/logger'; +import { logger } from '../../src/logger'; import * as testUtils from "../test-utils"; -import {TestClient} from "../TestClient"; -import {CRYPTO_ENABLED} from "../../src/client"; +import { TestClient } from "../TestClient"; +import { CRYPTO_ENABLED } from "../../src/client"; let aliTestClient; const roomId = "!room:localhost"; @@ -75,7 +75,7 @@ function expectAliQueryKeys() { ); const result = {}; result[bobUserId] = bobKeys; - return {device_keys: result}; + return { device_keys: result }; }); return aliTestClient.httpBackend.flush("/keys/query", 1); } @@ -103,7 +103,7 @@ function expectBobQueryKeys() { ); const result = {}; result[aliUserId] = aliKeys; - return {device_keys: result}; + return { device_keys: result }; }); return bobTestClient.httpBackend.flush("/keys/query", 1); } @@ -132,7 +132,7 @@ function expectAliClaimKeys() { result[bobUserId] = {}; result[bobUserId][bobDeviceId] = {}; result[bobUserId][bobDeviceId][keyId] = keys[keyId]; - return {one_time_keys: result}; + return { one_time_keys: result }; }); }).then(() => { // it can take a while to process the key query, so give it some extra @@ -144,7 +144,6 @@ function expectAliClaimKeys() { }); } - function aliDownloadsKeys() { // can't query keys before bob has uploaded them expect(bobTestClient.getSigningKey()).toBeTruthy(); @@ -269,7 +268,7 @@ function expectBobSendMessageRequest() { function sendMessage(client) { return client.sendMessage( - roomId, {msgtype: "m.text", body: "Hello, World"}, + roomId, { msgtype: "m.text", body: "Hello, World" }, ); } @@ -357,7 +356,6 @@ function recvMessage(httpBackend, client, sender, message) { }); } - /** * Send an initial sync response to the client (which just includes the member * list for our test room). @@ -395,7 +393,6 @@ function firstSync(testClient) { return testClient.flushSync(); } - describe("MatrixClient crypto", function() { if (!CRYPTO_ENABLED) { return; @@ -477,7 +474,7 @@ describe("MatrixClient crypto", function() { ).respond(200, function(path, content) { const result = {}; result[bobUserId] = bobKeys; - return {device_keys: result}; + return { device_keys: result }; }); return Promise.all([ @@ -519,7 +516,7 @@ describe("MatrixClient crypto", function() { ).respond(200, function(path, content) { const result = {}; result[bobUserId] = bobKeys; - return {device_keys: result}; + return { device_keys: result }; }); return Promise.all([ @@ -533,7 +530,6 @@ describe("MatrixClient crypto", function() { }); }); - it("Bob starts his client and uploads device keys and one-time keys", function() { return Promise.resolve() .then(() => bobTestClient.start()) @@ -545,7 +541,7 @@ describe("MatrixClient crypto", function() { }); it("Ali sends a message", function() { - aliTestClient.expectKeyQuery({device_keys: {[aliUserId]: {}}}); + aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} } }); return Promise.resolve() .then(() => aliTestClient.start()) .then(() => bobTestClient.start()) @@ -555,7 +551,7 @@ describe("MatrixClient crypto", function() { }); it("Bob receives a message", function() { - aliTestClient.expectKeyQuery({device_keys: {[aliUserId]: {}}}); + aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} } }); return Promise.resolve() .then(() => aliTestClient.start()) .then(() => bobTestClient.start()) @@ -566,7 +562,7 @@ describe("MatrixClient crypto", function() { }); it("Bob receives a message with a bogus sender", function() { - aliTestClient.expectKeyQuery({device_keys: {[aliUserId]: {}}}); + aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} } }); return Promise.resolve() .then(() => aliTestClient.start()) .then(() => bobTestClient.start()) @@ -620,7 +616,7 @@ describe("MatrixClient crypto", function() { }); it("Ali blocks Bob's device", function() { - aliTestClient.expectKeyQuery({device_keys: {[aliUserId]: {}}}); + aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} } }); return Promise.resolve() .then(() => aliTestClient.start()) .then(() => bobTestClient.start()) @@ -640,7 +636,7 @@ describe("MatrixClient crypto", function() { }); it("Bob receives two pre-key messages", function() { - aliTestClient.expectKeyQuery({device_keys: {[aliUserId]: {}}}); + aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} } }); return Promise.resolve() .then(() => aliTestClient.start()) .then(() => bobTestClient.start()) @@ -653,8 +649,8 @@ describe("MatrixClient crypto", function() { }); it("Bob replies to the message", function() { - aliTestClient.expectKeyQuery({device_keys: {[aliUserId]: {}}}); - bobTestClient.expectKeyQuery({device_keys: {[bobUserId]: {}}}); + aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} } }); + bobTestClient.expectKeyQuery({ device_keys: { [bobUserId]: {} } }); return Promise.resolve() .then(() => aliTestClient.start()) .then(() => bobTestClient.start()) @@ -672,7 +668,7 @@ describe("MatrixClient crypto", function() { it("Ali does a key query when encryption is enabled", function() { // enabling encryption in the room should make alice download devices // for both members. - aliTestClient.expectKeyQuery({device_keys: {[aliUserId]: {}}}); + aliTestClient.expectKeyQuery({ device_keys: { [aliUserId]: {} } }); return Promise.resolve() .then(() => aliTestClient.start()) .then(() => firstSync(aliTestClient)) diff --git a/src/crypto/OutgoingRoomKeyRequestManager.js b/src/crypto/OutgoingRoomKeyRequestManager.js index 899c3ca96..7f64b5313 100644 --- a/src/crypto/OutgoingRoomKeyRequestManager.js +++ b/src/crypto/OutgoingRoomKeyRequestManager.js @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {logger} from '../logger'; +import { logger } from '../logger'; /** * Internal module. Management of outgoing room key requests. diff --git a/src/models/room.js b/src/models/room.js index 8273d0e8e..805043587 100644 --- a/src/models/room.js +++ b/src/models/room.js @@ -20,17 +20,17 @@ limitations under the License. * @module models/room */ -import {EventEmitter} from "events"; -import {EventTimelineSet} from "./event-timeline-set"; -import {EventTimeline} from "./event-timeline"; -import {getHttpUriForMxc} from "../content-repo"; +import { EventEmitter } from "events"; +import { EventTimelineSet } from "./event-timeline-set"; +import { EventTimeline } from "./event-timeline"; +import { getHttpUriForMxc } from "../content-repo"; import * as utils from "../utils"; -import {EventStatus, MatrixEvent} from "./event"; -import {RoomMember} from "./room-member"; -import {RoomSummary} from "./room-summary"; -import {logger} from '../logger'; -import {ReEmitter} from '../ReEmitter'; -import {EventType, RoomCreateTypeField, RoomType} from "../@types/event"; +import { EventStatus, MatrixEvent } from "./event"; +import { RoomMember } from "./room-member"; +import { RoomSummary } from "./room-summary"; +import { logger } from '../logger'; +import { ReEmitter } from '../ReEmitter'; +import { EventType, RoomCreateTypeField, RoomType } from "../@types/event"; import { normalize } from "../utils"; // These constants are used as sane defaults when the homeserver doesn't support @@ -59,7 +59,6 @@ function synthesizeReceipt(userId, event, receiptType) { return new MatrixEvent(fakeReceipt); } - /** * Construct a new Room. * @@ -234,7 +233,6 @@ function pendingEventsKey(roomId) { utils.inherits(Room, EventEmitter); - /** * Bulk decrypt critical events in a room * @@ -495,7 +493,6 @@ Room.prototype.getLiveTimeline = function() { return this.getUnfilteredTimelineSet().getLiveTimeline(); }; - /** * Get the timestamp of the last message in the room * @@ -634,13 +631,12 @@ Room.prototype._loadMembersFromServer = async function() { at: lastSyncToken, }); const path = utils.encodeUri("/rooms/$roomId/members?" + queryString, - {$roomId: this.roomId}); + { $roomId: this.roomId }); const http = this._client._http; const response = await http.authedRequest(undefined, "GET", path); return response.chunk; }; - Room.prototype._loadMembers = async function() { // were the members loaded from the server? let fromServer = false; @@ -653,7 +649,7 @@ Room.prototype._loadMembers = async function() { `members from server for room ${this.roomId}`); } const memberEvents = rawMembersEvents.map(this._client.getEventMapper()); - return {memberEvents, fromServer}; + return { memberEvents, fromServer }; }; /** @@ -1125,7 +1121,6 @@ Room.prototype.getInvitedAndJoinedMemberCount = function() { return calculateRoomName(this, userId, true); }; - /** * Check if the given user_id has the given membership state. * @param {string} userId The user ID to check. @@ -1282,7 +1277,6 @@ Room.prototype._addLiveEvent = function(event, duplicateStrategy, fromCache) { } }; - /** * Add a pending outgoing event to this room. * @@ -1693,7 +1687,6 @@ Room.prototype.removeEvent = function(eventId) { return removedAny; }; - /** * Recalculate various aspects of the room, including the room name and * room summary. Call this any time the room's current state is modified. @@ -1918,7 +1911,6 @@ Room.prototype._buildReceiptCache = function(receipts) { return receiptCacheByEventId; }; - /** * Add a temporary local-echo receipt to the room to reflect in the * client the fact that we've sent one. @@ -1976,7 +1968,6 @@ Room.prototype.getAccountData = function(type) { return this.accountData[type]; }; - /** * Returns whether the syncing user has permission to send a message in the room * @return {boolean} true if the user should be permitted to send diff --git a/src/models/search-result.js b/src/models/search-result.js index 2250e786f..fcf8bb43f 100644 --- a/src/models/search-result.js +++ b/src/models/search-result.js @@ -19,7 +19,7 @@ limitations under the License. * @module models/search-result */ -import {EventContext} from "./event-context"; +import { EventContext } from "./event-context"; /** * Construct a new SearchResult diff --git a/src/store/memory.js b/src/store/memory.js index 1b582ee43..809696b25 100644 --- a/src/store/memory.js +++ b/src/store/memory.js @@ -22,7 +22,7 @@ limitations under the License. * @module store/memory */ -import {User} from "../models/user"; +import { User } from "../models/user"; function isValidFilterId(filterId) { const isValidStr = typeof filterId === "string" && From ff344bc110adaea0d40ceabec2d7ee1f28b2009e Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 27 May 2021 17:51:03 +0100 Subject: [PATCH 3/6] Switch lint parsers --- src/logger.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/logger.ts b/src/logger.ts index 005d27665..bd1f98b25 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -36,11 +36,11 @@ const DEFAULT_NAMESPACE = "matrix"; // when logging so we always get the current value of console methods. log.methodFactory = function(methodName, logLevel, loggerName) { return function(...args) { - /* eslint-disable @babel/no-invalid-this */ + /* eslint-disable @typescript-eslint/no-invalid-this */ if (this.prefix) { args.unshift(this.prefix); } - /* eslint-enable @babel/no-invalid-this */ + /* eslint-enable @typescript-eslint/no-invalid-this */ const supportedByConsole = methodName === "error" || methodName === "warn" || methodName === "trace" || From 8805dd8c01d923f4f77b7bcdaf5fa016473d946c Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 28 May 2021 11:15:10 +0100 Subject: [PATCH 4/6] Auto-fix lint errors --- spec/unit/relations.spec.ts | 2 +- spec/unit/webrtc/call.spec.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/unit/relations.spec.ts b/spec/unit/relations.spec.ts index 3be34f332..c8de24292 100644 --- a/spec/unit/relations.spec.ts +++ b/spec/unit/relations.spec.ts @@ -72,7 +72,7 @@ describe("Relations", function() { } }); - it("should emit created regardless of ordering", async function () { + it("should emit created regardless of ordering", async function() { const targetEvent = new MatrixEvent({ "sender": "@bob:example.com", "type": "m.room.message", diff --git a/spec/unit/webrtc/call.spec.ts b/spec/unit/webrtc/call.spec.ts index e5ef6de87..100f334ec 100644 --- a/spec/unit/webrtc/call.spec.ts +++ b/spec/unit/webrtc/call.spec.ts @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {TestClient} from '../../TestClient'; -import {MatrixCall, CallErrorCode, CallEvent} from '../../../src/webrtc/call'; +import { TestClient } from '../../TestClient'; +import { MatrixCall, CallErrorCode, CallEvent } from '../../../src/webrtc/call'; const DUMMY_SDP = ( "v=0\r\n" + From 4dc21674d5d9ba26da657633902e094ac56e1c45 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 28 May 2021 11:30:20 +0100 Subject: [PATCH 5/6] Fix log usage --- src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e599e0065..93fca0a97 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,6 +16,7 @@ limitations under the License. import * as matrixcs from "./matrix"; import * as utils from "./utils"; +import { logger } from './logger'; import request from "request"; matrixcs.request(request); @@ -25,7 +26,7 @@ try { const crypto = require('crypto'); utils.setCrypto(crypto); } catch (err) { - console.log('nodejs was compiled without crypto support'); + logger.log('nodejs was compiled without crypto support'); } export * from "./matrix"; From 6dca8ac460203dde8bcf94fc9d116132544ddc45 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 28 May 2021 11:39:06 +0100 Subject: [PATCH 6/6] Switch to new Babel lint config This also adjusts the TypeScript project lint config to cover *.ts test files too. --- .eslintrc.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c0c6be63a..1735739e3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,7 +2,9 @@ module.exports = { plugins: [ "matrix-org", ], - extends: ["plugin:matrix-org/babel"], + extends: [ + "plugin:matrix-org/babel", + ], env: { browser: true, node: true, @@ -31,14 +33,26 @@ module.exports = { "no-console": "error", }, overrides: [{ - "files": ["src/**/*.ts"], - "extends": ["plugin:matrix-org/typescript"], - "rules": { + files: [ + "**/*.ts", + ], + extends: [ + "plugin:matrix-org/typescript", + ], + rules: { + // TypeScript has its own version of this + "@babel/no-invalid-this": "off", + // We're okay being explicit at the moment "@typescript-eslint/no-empty-interface": "off", - // While we're converting to ts we make heavy use of this + // We disable this while we're transitioning "@typescript-eslint/no-explicit-any": "off", + // We'd rather not do this but we do + "@typescript-eslint/ban-ts-comment": "off", + "quotes": "off", + // We use a `logger` intermediary module + "no-console": "error", }, }], };