From 7343832f7a95b9db3aa2fa8d8ac9748a9db3a0ad Mon Sep 17 00:00:00 2001 From: Christian Paul <christianp@matrix.org> Date: Wed, 2 Dec 2020 13:52:05 +0100 Subject: [PATCH] Include test/**/* in the TypeScript project for linting; fix remaining errors --- .eslintrc | 13 ++++++++++++- src/db/postgres.ts | 8 ++++---- src/db/roomstore.ts | 2 +- test/db/test_roomstore.ts | 1 + test/mocks/appservicemock.ts | 2 +- tsconfig.json | 1 + 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.eslintrc b/.eslintrc index 7916d95..256c63e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -42,5 +42,16 @@ "@typescript-eslint/member-delimiter-style": "off", "@typescript-eslint/no-unused-expressions": "off", "@typescript-eslint/interface-name-prefix": "off" - } + }, + "overrides": [ + { + "files": [ + "test/**/*" + ], + "rules": { + "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/no-explicit-any": "off" + } + } + ] } diff --git a/src/db/postgres.ts b/src/db/postgres.ts index 26ebcaf..da0d800 100644 --- a/src/db/postgres.ts +++ b/src/db/postgres.ts @@ -25,7 +25,7 @@ const pgp: pgPromise.IMain = pgPromise({ export class Postgres implements IDatabaseConnector { public static ParameterizeSql(sql: string): string { - return sql.replace(/\$((\w|\d|_)+)+/g, (k) => { + return sql.replace(/\$((\w|\d|_)+)+/g, (k: string) => { return `\${${k.substr("$".length)}}`; }); } @@ -35,7 +35,8 @@ export class Postgres implements IDatabaseConnector { constructor(private connectionString: string) { } - public Open() { + + public Open(): void { // Hide username:password const logConnString = this.connectionString.substr( this.connectionString.indexOf("@") || 0, @@ -63,7 +64,7 @@ export class Postgres implements IDatabaseConnector { public async Run(sql: string, parameters?: ISqlCommandParameters): Promise<void> { log.silly("Run:", sql); - return this.db.oneOrNone(Postgres.ParameterizeSql(sql), parameters).then(() => {}); + await this.db.oneOrNone(Postgres.ParameterizeSql(sql), parameters); } public async Close(): Promise<void> { @@ -73,6 +74,5 @@ export class Postgres implements IDatabaseConnector { public async Exec(sql: string): Promise<void> { log.silly("Exec:", sql); await this.db.none(sql); - return; } } diff --git a/src/db/roomstore.ts b/src/db/roomstore.ts index aca6177..dc44216 100644 --- a/src/db/roomstore.ts +++ b/src/db/roomstore.ts @@ -237,7 +237,7 @@ export class DbRoomStore { try { await this.db.Run(`INSERT INTO room_entries VALUES ($id, $matrix, $remote)`, values); - log.verbose(`Created new entry ${ values.id}`); + log.verbose(`Created new entry ${values.id}`); } catch (ex) { log.error("Failed to insert room entry", ex); throw Error("Failed to insert room entry"); diff --git a/test/db/test_roomstore.ts b/test/db/test_roomstore.ts index 29fef59..921550d 100644 --- a/test/db/test_roomstore.ts +++ b/test/db/test_roomstore.ts @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +/* eslint-disable @typescript-eslint/camelcase */ import * as Chai from "chai"; import { DiscordStore, CURRENT_SCHEMA } from "../../src/store"; diff --git a/test/mocks/appservicemock.ts b/test/mocks/appservicemock.ts index 5aaf9ca..4de03ee 100644 --- a/test/mocks/appservicemock.ts +++ b/test/mocks/appservicemock.ts @@ -240,7 +240,7 @@ class MatrixClientMock extends AppserviceMockBase { public async uploadContent(data: Buffer, contentType: string, filename: string = "noname") { this.funcCalled("uploadContent", data, contentType, filename); - return "mxc://" + filename; + return `mxc://${filename}`; } public mxcToHttp(mxcUrl: string) { diff --git a/tsconfig.json b/tsconfig.json index e57e451..19323e4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,7 @@ "compileOnSave": true, "include": [ "src/**/*", + "test/**/*", "tools/**/*", ] } -- GitLab