Skip to content

Commit ae38d86

Browse files
authored
[linting] Enable eslint/no-unsafe-argument (#18965)
1 parent 38f02bd commit ae38d86

File tree

65 files changed

+281
-212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+281
-212
lines changed

components/gitpod-db/.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
},
1111
"rules": {
1212
"no-var": "error",
13+
"no-void": "error",
1314
"prefer-const": "error",
1415
"@typescript-eslint/ban-ts-comment": "off",
1516
"@typescript-eslint/ban-types": "off",
1617
"@typescript-eslint/explicit-module-boundary-types": "off",
1718
"@typescript-eslint/no-empty-function": "off",
1819
"@typescript-eslint/no-empty-interface": "off",
1920
"@typescript-eslint/no-explicit-any": "off",
21+
"@typescript-eslint/no-floating-promises": "error",
2022
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
2123
"@typescript-eslint/no-inferrable-types": "off",
2224
"@typescript-eslint/no-misused-promises": [
@@ -28,6 +30,7 @@
2830
"@typescript-eslint/no-namespace": "off",
2931
"@typescript-eslint/no-non-null-assertion": "off",
3032
"@typescript-eslint/no-this-alias": "off",
33+
"@typescript-eslint/no-unsafe-argument": "error",
3134
"@typescript-eslint/no-unused-vars": [
3235
"error",
3336
{

components/gitpod-db/src/migrate-migrations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { TypeORM } from "./typeorm/typeorm";
88
import { Config } from "./config";
99
import { MigrateMigrations0_2_0 } from "./typeorm/migrate-migrations-0_2_0";
10+
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
1011

1112
async function migrateMigrationsTable() {
1213
const config = new Config();
@@ -17,7 +18,7 @@ async function migrateMigrationsTable() {
1718
const migration_0_2_0 = new MigrateMigrations0_2_0();
1819
await migration_0_2_0.up(runner);
1920

20-
conn.close();
21+
conn.close().catch((err) => log.error("cannot close connection", err));
2122
console.log("successfully migrated 'migrations' table.");
2223
}
2324

components/gitpod-db/src/periodic-deleter.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,13 @@ export class PeriodicDbDeleter {
3939
const pendingDeletions: Promise<void>[] = [];
4040
for (const { deletions } of toBeDeleted.reverse()) {
4141
for (const deletion of deletions) {
42-
pendingDeletions.push(
43-
this.query(deletion).catch((err) =>
44-
log.error(
45-
`[PeriodicDbDeleter] sync error`,
46-
{
47-
periodicDeleterTickId: tickID,
48-
query: deletion,
49-
},
50-
err,
51-
),
52-
),
42+
const promise: Promise<void> = this.query(deletion).catch((err) =>
43+
log.error(`[PeriodicDbDeleter] sync error`, err, {
44+
periodicDeleterTickId: tickID,
45+
query: deletion,
46+
}),
5347
);
48+
pendingDeletions.push(promise);
5449
}
5550
}
5651
await Promise.all(pendingDeletions);

components/gitpod-db/src/redis/publisher.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class TestRedisPublisher {
3131

3232
@test public publishInstanceUpdate() {
3333
const publisher = this.container.get(RedisPublisher);
34-
expect(() => {
35-
publisher.publishInstanceUpdate({
34+
expect(async () => {
35+
await publisher.publishInstanceUpdate({
3636
ownerID: "123-owner",
3737
instanceID: "123",
3838
workspaceID: "foo-bar-123",

components/gitpod-db/src/tables.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ class TablesSpec {
1919
@test(timeout(10000))
2020
public async createAndFindATeam() {
2121
const thing = new GitpodTableDescriptionProvider();
22-
try {
23-
thing.getSortedTables();
24-
} catch (error) {
25-
expect.fail(error);
26-
}
22+
expect(() => thing.getSortedTables()).to.not.throw();
2723
}
2824
}
2925

components/gitpod-db/src/test/reset-db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function resetDB(typeorm: TypeORM) {
1212
const conn = await typeorm.getConnection();
1313
const users = await conn.getRepository(DBUser).find();
1414
// delete all users except the builtin users
15-
conn.getRepository(DBUser).remove(users.filter((u) => !isBuiltinUser(u.id)));
15+
await conn.getRepository(DBUser).remove(users.filter((u) => !isBuiltinUser(u.id)));
1616

1717
const deletions = conn.entityMetadatas
1818
.filter((meta) => meta.tableName !== "d_b_user")

components/gitpod-db/src/traced-db.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class DBWithTracing<T> {
1717
public trace(ctx: TraceContext): T {
1818
return new Proxy(this.db, {
1919
get: (_target: any, name: string) => {
20+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
2021
const f = Reflect.get(_target, name);
2122
if (!f) {
2223
return undefined;

components/gitpod-db/src/typeorm/team-db-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export class TeamDBImpl extends TransactionalDBImpl<TeamDB> implements TeamDB {
254254
const orgSettings = await orgSettingsRepo.findOne({ where: { orgId } });
255255
if (orgSettings) {
256256
orgSettings.deleted = true;
257-
orgSettingsRepo.save(orgSettings);
257+
await orgSettingsRepo.save(orgSettings);
258258
}
259259
}
260260

components/gitpod-db/src/typeorm/transformer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export namespace Transformer {
6464
},
6565
from(value: any): any {
6666
// From TIMESTAMP to ISO string
67+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
6768
return new Date(Date.parse(value)).toISOString();
6869
},
6970
};
@@ -74,6 +75,7 @@ export namespace Transformer {
7475
return JSON.stringify(value || defaultValue);
7576
},
7677
from(value: any): any {
78+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
7779
return JSON.parse(value);
7880
},
7981
};
@@ -85,6 +87,7 @@ export namespace Transformer {
8587
return encryptionServiceProvider().encrypt(value);
8688
},
8789
from(value: any): any {
90+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
8891
return encryptionServiceProvider().decrypt(value);
8992
},
9093
};

components/gitpod-db/src/typeorm/user-db-impl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl<UserDB> implements Us
379379
}
380380
const res = await userRepo.query(query);
381381
const count = res[0].cnt;
382+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
382383
return Number.parseInt(count);
383384
}
384385

@@ -598,7 +599,7 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl<UserDB> implements Us
598599
}
599600
async revoke(accessTokenToken: OAuthToken): Promise<void> {
600601
const tokenHash = crypto.createHash("sha256").update(accessTokenToken.accessToken, "utf8").digest("hex");
601-
this.deleteGitpodToken(tokenHash);
602+
await this.deleteGitpodToken(tokenHash);
602603
}
603604
async isRefreshTokenRevoked(refreshToken: OAuthToken): Promise<boolean> {
604605
return Date.now() > (refreshToken.refreshTokenExpiresAt?.getTime() ?? 0);

components/gitpod-db/src/typeorm/workspace-db-impl.ts

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import {
88
AdminGetWorkspacesQuery,
9+
CommitContext,
910
PrebuildInfo,
1011
PrebuiltWorkspace,
1112
PrebuiltWorkspaceState,
@@ -143,9 +144,10 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
143144

144145
// `cloneUrl` is stored redundandly to optimize for `getWorkspaceCountByCloneURL`.
145146
// As clone URLs are lesser constrained we want to shorten the value to work well with the indexed column.
146-
const cloneUrl: string = this.toCloneUrl255((workspace as any).context?.repository?.cloneUrl || "");
147-
148-
dbWorkspace.cloneUrl = cloneUrl;
147+
if (CommitContext.is(dbWorkspace.context)) {
148+
const cloneUrl = this.toCloneUrl255(dbWorkspace.context.repository.cloneUrl);
149+
dbWorkspace.cloneUrl = cloneUrl;
150+
}
149151
return await workspaceRepo.save(dbWorkspace);
150152
}
151153

@@ -167,17 +169,12 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
167169
}
168170

169171
public async findByInstanceId(instanceId: string): Promise<MaybeWorkspace> {
170-
const workspaceRepo = await this.getWorkspaceRepo();
171-
const maybeRawWorkspaces = (await workspaceRepo.query(
172-
`SELECT ws.* FROM d_b_workspace as ws
173-
LEFT OUTER JOIN d_b_workspace_instance as wsi ON wsi.workspaceId = ws.id
174-
WHERE wsi.id = ?;`,
175-
[instanceId],
176-
)) as object[];
177-
if (!maybeRawWorkspaces || maybeRawWorkspaces.length !== 1) {
172+
const instanceRepo = await this.getWorkspaceInstanceRepo();
173+
const instance = await instanceRepo.findOne(instanceId);
174+
if (!instance) {
178175
return undefined;
179176
}
180-
return this.makeWorkspace(maybeRawWorkspaces[0]);
177+
return this.findById(instance.workspaceId);
181178
}
182179

183180
public async find(options: FindWorkspacesOptions): Promise<WorkspaceInfo[]> {
@@ -265,16 +262,6 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
265262
});
266263
}
267264

268-
private makeWorkspace(raw: any): DBWorkspace | undefined {
269-
if (!raw) return undefined;
270-
return {
271-
...raw,
272-
config: JSON.parse(raw.config),
273-
context: JSON.parse(raw.context),
274-
pinned: (raw.pinned && JSON.parse(raw.pinned)) || undefined,
275-
};
276-
}
277-
278265
public async updateLastHeartbeat(
279266
instanceId: string,
280267
userId: string,
@@ -285,7 +272,7 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
285272
"INSERT INTO d_b_workspace_instance_user(instanceId, userId, lastSeen) VALUES (?, ?, timestamp ?) ON DUPLICATE KEY UPDATE lastSeen = timestamp ?, wasClosed = ?";
286273
const lastSeen = this.toTimestampString(newHeartbeat);
287274
const workspaceInstanceUserRepo = await this.getWorkspaceInstanceUserRepo();
288-
workspaceInstanceUserRepo.query(query, [instanceId, userId, lastSeen, lastSeen, wasClosed || false]);
275+
await workspaceInstanceUserRepo.query(query, [instanceId, userId, lastSeen, lastSeen, wasClosed || false]);
289276
}
290277

291278
private toTimestampString(date: Date) {
@@ -302,6 +289,7 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
302289

303290
if (result && result.length > 0 && result[0].lastSeen) {
304291
return {
292+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
305293
lastSeen: new Date(result[0].lastSeen),
306294
wasClosed: Boolean(result[0].wasClosed),
307295
};
@@ -401,7 +389,7 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
401389
userId?: string,
402390
includeStopping: boolean = false,
403391
): Promise<RunningWorkspaceInfo[]> {
404-
const params: any = {};
392+
const params: { region?: string } = {};
405393
const conditions = ["wsi.phasePersisted != 'stopped'", "wsi.deleted != TRUE"];
406394
if (!includeStopping) {
407395
// This excludes instances in a 'stopping' phase
@@ -411,7 +399,7 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
411399
params.region = workspaceClusterName;
412400
conditions.push("wsi.region = :region");
413401
}
414-
const joinParams: any = {};
402+
const joinParams: { userId?: string } = {};
415403
const joinConditions = [];
416404
if (userId) {
417405
joinParams.userId = userId;
@@ -501,6 +489,7 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
501489
resultSessions.push({
502490
workspace: {
503491
id: session.ws_id,
492+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
504493
context: JSON.parse(session.ws_context),
505494
contextURL: session.ws_contextURL,
506495
type: session.ws_type,
@@ -980,6 +969,7 @@ export class TypeORMWorkspaceDBImpl extends TransactionalDBImpl<WorkspaceDB> imp
980969
: "wsi.id = (SELECT i.id FROM d_b_workspace_instance AS i WHERE i.workspaceId = ws.id ORDER BY i.creationTime DESC LIMIT 1)"
981970
}`,
982971
)
972+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
983973
.where(whereConditions.join(" AND "), whereConditionParams)
984974
.orderBy(orderField, orderDir)
985975
.take(limit)

components/gitpod-db/src/wait-for-db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ function connectOrReschedule(attempt: number) {
3535
}
3636
}
3737

38-
function rescheduleConnectionAttempt(attempt: number, err: Error) {
38+
function rescheduleConnectionAttempt(attempt: number, err: unknown) {
3939
if (attempt == totalAttempts) {
40-
console.log(`Could not connect within ${totalAttempts} attempts. Stopping.`);
40+
console.log(`Could not connect within ${totalAttempts} attempts. Stopping.`, err);
4141
process.exit(1);
4242
}
4343
console.log(`Connection attempt ${attempt}/${totalAttempts} failed. Retrying in ${retryPeriod / 1000} seconds.`);

components/gitpod-db/src/workspace-db.spec.db.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ class WorkspaceDBSpec {
4141
tasks: [],
4242
},
4343
projectId: this.projectAID,
44-
context: { title: "example" },
44+
context: <CommitContext>{
45+
title: "example",
46+
repository: {
47+
cloneUrl: "https://github.com/gitpod-io/gitpod",
48+
},
49+
revision: "abc",
50+
},
4551
contextURL: "example.org",
4652
description: "blabla",
4753
ownerId: this.userId,
@@ -105,7 +111,13 @@ class WorkspaceDBSpec {
105111
tasks: [],
106112
},
107113
projectId: this.projectBID,
108-
context: { title: "example" },
114+
context: <CommitContext>{
115+
title: "example",
116+
repository: {
117+
cloneUrl: "https://github.com/gitpod-io/gitpod",
118+
},
119+
revision: "abc",
120+
},
109121
contextURL: "https://github.com/gitpod-io/gitpod",
110122
description: "Gitpod",
111123
ownerId: this.userId,
@@ -145,7 +157,13 @@ class WorkspaceDBSpec {
145157
image: "",
146158
tasks: [],
147159
},
148-
context: { title: "example" },
160+
context: <CommitContext>{
161+
title: "example",
162+
repository: {
163+
cloneUrl: "https://github.com/gitpod-io/gitpod",
164+
},
165+
revision: "abc",
166+
},
149167
contextURL: "example.org",
150168
description: "blabla",
151169
ownerId: this.userId,
@@ -206,6 +224,16 @@ class WorkspaceDBSpec {
206224
fail("Rollback failed");
207225
}
208226

227+
@test(timeout(10000))
228+
public async testFindByInstanceId() {
229+
await this.db.transaction(async (db) => {
230+
await Promise.all([db.store(this.ws), db.storeInstance(this.wsi1)]);
231+
const dbResult = await db.findByInstanceId(this.wsi1.id);
232+
const expected = await db.findById(this.wsi1.workspaceId);
233+
expect(dbResult).to.deep.eq(expected);
234+
});
235+
}
236+
209237
@test(timeout(10000))
210238
public async testFindPrebuildsForGC_oldPrebuildNoUsage() {
211239
await this.createPrebuild(2);
@@ -583,6 +611,7 @@ class WorkspaceDBSpec {
583611
repository: {
584612
cloneUrl: inactiveRepo,
585613
},
614+
revision: "abc",
586615
},
587616
config: {},
588617
type: "regular",
@@ -599,6 +628,7 @@ class WorkspaceDBSpec {
599628
repository: {
600629
cloneUrl: activeRepo,
601630
},
631+
revision: "abc",
602632
},
603633
config: {},
604634
type: "regular",

components/gitpod-protocol/.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
},
1111
"rules": {
1212
"no-var": "error",
13+
"no-void": "error",
1314
"prefer-const": "error",
1415
"@typescript-eslint/ban-ts-comment": "off",
1516
"@typescript-eslint/ban-types": "off",
1617
"@typescript-eslint/explicit-module-boundary-types": "off",
1718
"@typescript-eslint/no-empty-function": "off",
1819
"@typescript-eslint/no-empty-interface": "off",
1920
"@typescript-eslint/no-explicit-any": "off",
21+
"@typescript-eslint/no-floating-promises": "error",
2022
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
2123
"@typescript-eslint/no-inferrable-types": "off",
2224
"@typescript-eslint/no-misused-promises": [
@@ -28,6 +30,7 @@
2830
"@typescript-eslint/no-namespace": "off",
2931
"@typescript-eslint/no-non-null-assertion": "off",
3032
"@typescript-eslint/no-this-alias": "off",
33+
"@typescript-eslint/no-unsafe-argument": "error",
3134
"@typescript-eslint/no-unused-vars": [
3235
"error",
3336
{

components/gitpod-protocol/src/gitpod-file-parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { WorkspaceConfig, PortRangeConfig } from "./protocol";
1313
export type MaybeConfig = WorkspaceConfig | undefined;
1414

1515
const schema = require("../data/gitpod-schema.json");
16-
const validate = new Ajv().compile(schema);
16+
const validate = new Ajv().compile(schema as object);
1717
const defaultParseOptions = {
1818
acceptPortRanges: false,
1919
};
@@ -33,6 +33,7 @@ export class GitpodFileParser {
3333
};
3434
try {
3535
const parsedConfig = yaml.safeLoad(content) as any;
36+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
3637
validate(parsedConfig);
3738
const validationErrors = validate.errors ? validate.errors.map((e) => e.message || e.keyword) : undefined;
3839
if (validationErrors && validationErrors.length > 0) {

0 commit comments

Comments
 (0)