Skip to content

Commit b8daf77

Browse files
committed
chore(eslint): add stylistic plugin and format
1 parent c16102d commit b8daf77

27 files changed

+1049
-982
lines changed

app/authentication.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export async function expressAuthentication(
1111
) {
1212
if (securityName !== 'userAuthJwt' && securityName !== 'backendAuthToken') {
1313
// NOTE: Express error handler handles AuthError
14-
throw new AuthError('Security name should either be "userAuthJwt" or "backendAuthToken"', 401)
14+
throw new AuthError('Security name should either be "userAuthJwt" or "backendAuthToken"', 401);
1515
}
1616

1717
const authHeader = request.header('Authorization');
1818
if (!authHeader || !authHeader.startsWith('Bearer ')) {
1919
// NOTE: Express error handler handles AuthError
20-
throw new AuthError('Missing or invalid Authorization header', 401)
20+
throw new AuthError('Missing or invalid Authorization header', 401);
2121
}
2222

2323
const token = authHeader.replace(/^Bearer /, '');
@@ -32,7 +32,7 @@ export async function expressAuthentication(
3232

3333
if (tokenData instanceof Error) {
3434
// NOTE: Express error handler handles AuthError
35-
throw new AuthError(tokenData.message, 401)
35+
throw new AuthError(tokenData.message, 401);
3636
}
3737

3838
// TODO: match scope with groups
@@ -44,10 +44,11 @@ export async function expressAuthentication(
4444
scope: undefined,
4545
token,
4646
};
47-
} else {
47+
}
48+
else {
4849
if (token !== env.SERVICE_TOKEN) {
4950
// NOTE: Express error handler handles AuthError
50-
throw new AuthError('Service token is not correct', 401)
51+
throw new AuthError('Service token is not correct', 401);
5152
}
5253
// TODO: match scope with token scope
5354
return {

app/core/express.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import express from 'express';
2-
import { ValidateError } from "tsoa";
2+
import { ValidateError } from 'tsoa';
33
import expressWebsockets from 'express-ws';
44
import fs from 'fs';
55
import yaml from 'yaml';
@@ -10,14 +10,14 @@ import cors from 'cors';
1010
import * as Helmet from 'helmet';
1111

1212
import { AuthError, NotFoundError } from '../utils/error.ts';
13-
import { RegisterRoutes } from "../../generated/routes.ts";
13+
import { RegisterRoutes } from '../../generated/routes.ts';
1414

1515
// NOTE: could not import helmet normally!
1616
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1717
const helmet = Helmet.default as unknown as () => any;
1818

1919
interface InitConfig {
20-
allowedOrigins: string[],
20+
allowedOrigins: string[];
2121
}
2222

2323
export function initWsApp(
@@ -50,8 +50,8 @@ export function initWsApp(
5050
// NOTE: Using YAML because JSON giving error
5151
// https://gitlab.com/gitlab-org/gitlab/-/issues/379097
5252

53-
const file = fs.readFileSync('./generated/swagger.yaml', 'utf8')
54-
const swaggerDocument = yaml.parse(file)
53+
const file = fs.readFileSync('./generated/swagger.yaml', 'utf8');
54+
const swaggerDocument = yaml.parse(file);
5555

5656
const swaggerHtml = swaggerUi.generateHTML(swaggerDocument);
5757
return res.send(swaggerHtml);
@@ -66,7 +66,7 @@ export function initWsApp(
6666
expressWsApp.use(
6767
(_req: express.Request, res: express.Response) => {
6868
res.status(404).send({
69-
message: "Resource not found",
69+
message: 'Resource not found',
7070
});
7171
},
7272
);
@@ -77,31 +77,31 @@ export function initWsApp(
7777
(err: unknown, _: express.Request, res: express.Response, __: express.NextFunction) => {
7878
if (err instanceof ValidateError) {
7979
return res.status(422).json({
80-
message: "Validation failed",
80+
message: 'Validation failed',
8181
details: err?.fields,
8282
});
8383
}
8484
if (err instanceof NotFoundError) {
8585
return res.status(404).json({
86-
message: "Resource not found",
86+
message: 'Resource not found',
8787
details: err.message,
8888
});
8989
}
9090
if (err instanceof AuthError) {
9191
return res.status(401).send({
92-
message: "Unauthorized",
92+
message: 'Unauthorized',
9393
details: err.message,
9494
});
9595
}
9696
if (err instanceof Error) {
9797
return res.status(500).json({
98-
message: "Internal server error",
98+
message: 'Internal server error',
9999
details: err.message,
100100
});
101101
}
102102
console.error('Uncaught error:', err);
103103
return res.status(500).json({
104-
message: "Internal server error",
104+
message: 'Internal server error',
105105
});
106106
},
107107
);

app/core/hocuspocus.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as Y from 'yjs'
2-
import { Connection, Hocuspocus, type Extension } from '@hocuspocus/server'
1+
import * as Y from 'yjs';
2+
import { Connection, Hocuspocus, type Extension } from '@hocuspocus/server';
33
import { Logger } from '@hocuspocus/extension-logger';
44
import { S3 } from '@hocuspocus/extension-s3';
55

@@ -58,15 +58,15 @@ export const hocuspocusServer = new Hocuspocus({
5858

5959
if (tokenData instanceof Error) {
6060
// NOTE: Throwing exception so that authenitcation fails
61-
throw Error("Token must be valid!");
61+
throw Error('Token must be valid!');
6262
}
6363

6464
// TODO: Update permissions from user group and pass permission function
6565
const id = tokenData['cognito:username'];
6666
const groups = tokenData['cognito:groups'];
6767
if (!groups || groups.length <= 0) {
6868
// NOTE: Throwing exception so that authenitcation fails
69-
throw Error("User should be in a group to edit documents");
69+
throw Error('User should be in a group to edit documents');
7070
}
7171

7272
return {
@@ -129,25 +129,25 @@ export const hocuspocusServer = new Hocuspocus({
129129
document.transact(() => {
130130
changeReportUpdateStates(
131131
document,
132-
(oldValue) => ({
132+
oldValue => ({
133133
no_of_updates: (oldValue?.no_of_updates ?? 0) + 1,
134134
last_updated: new Date().getTime(),
135135
}),
136136
);
137137
});
138138
},
139-
})
139+
});
140140

141141
// Get a document from hocuspocus or s3
142142
export async function getDoc(name: string) {
143-
const doc = hocuspocusServer.documents.get(name)
143+
const doc = hocuspocusServer.documents.get(name);
144144
if (doc) {
145145
return doc;
146146
}
147147

148148
const s3Doc = new Y.Doc();
149149
// eslint-disable-next-line @typescript-eslint/no-explicit-any
150-
const fetched = await s3Extension.configuration.fetch({ documentName: name, } as any);
150+
const fetched = await s3Extension.configuration.fetch({ documentName: name } as any);
151151
if (!fetched) {
152152
return new NotFoundError('Document not found');
153153
}

app/main.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const expressWsApp = initWsApp(
1313
(app) => {
1414
// Register collaboration endpoint to upgrade to websocket
1515
app.ws('/collaboration/', (websocket, request) => {
16-
hocuspocusServer.handleConnection(websocket, request)
16+
hocuspocusServer.handleConnection(websocket, request);
1717
});
1818
},
1919
);
@@ -23,17 +23,17 @@ const PORT = 8001;
2323
const expressServer = expressWsApp.listen(
2424
PORT,
2525
() => {
26-
console.log(`Listening on http://127.0.0.1:${PORT}`)
26+
console.log(`Listening on http://127.0.0.1:${PORT}`);
2727
},
2828
);
2929

3030
// Setup timeout to 1 minute
31-
expressServer.setTimeout( 1 * 60 * 1000)
31+
expressServer.setTimeout(1 * 60 * 1000);
3232

3333
// Handle sigterm
3434
process.on('SIGTERM', () => {
35-
console.log('SIGTERM signal received: closing HTTP server')
36-
expressServer.close(() => {
37-
console.log('HTTP server closed')
38-
})
39-
})
35+
console.log('SIGTERM signal received: closing HTTP server');
36+
expressServer.close(() => {
37+
console.log('HTTP server closed');
38+
});
39+
});

app/routes/collaboration.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { describe, test, expect, vi } from "vitest";
2-
import request from "supertest";
1+
import { describe, test, expect, vi } from 'vitest';
2+
import request from 'supertest';
33

44
import { initWsApp } from '../core/express.ts';
55
import * as jwt from '../../app/utils/jwt.ts';
@@ -11,14 +11,14 @@ const wsApp = initWsApp(
1111
() => {},
1212
);
1313

14-
describe("collaboration", () => {
15-
test("GET /collaboration/status with valid token", async () => {
14+
describe('collaboration', () => {
15+
test('GET /collaboration/status with valid token', async () => {
1616
const verifyJwtSpy = vi.spyOn(jwt, 'verifyJwt')
1717
.mockResolvedValueOnce(mockTokenPayload);
1818

1919
const res = await request(wsApp)
20-
.get("/collaboration/status")
21-
.set("Authorization", "Bearer my-valid-token")
20+
.get('/collaboration/status')
21+
.set('Authorization', 'Bearer my-valid-token');
2222

2323
expect(verifyJwtSpy).toHaveBeenCalledOnce();
2424

app/routes/collaboration.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Security,
66
Tags,
77
Example,
8-
} from "tsoa";
8+
} from 'tsoa';
99

1010
import { hocuspocusServer } from '../core/hocuspocus.ts';
1111

@@ -23,18 +23,18 @@ interface CollaborationStatus {
2323
openConnections: number;
2424
}
2525

26-
@Tags("Collaboration")
27-
@Route("/collaboration/")
26+
@Tags('Collaboration')
27+
@Route('/collaboration/')
2828
export class CollaborationController extends Controller {
29-
/**
29+
/**
3030
* Returns the current status of the collaboration server,
3131
* including the number of open documents and active connections.
3232
*/
33-
@Get("/status/")
34-
@Security("userAuthJwt", ["status/read"])
33+
@Get('/status/')
34+
@Security('userAuthJwt', ['status/read'])
3535
@Example<CollaborationStatus>({
3636
openDocs: 5,
37-
openConnections: 12
37+
openConnections: 12,
3838
})
3939
public async getCollaborationStatus(): Promise<CollaborationStatus> {
4040
return {

app/routes/doc.test.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Y from 'yjs';
2-
import { describe, test, expect, vi, afterEach } from "vitest";
3-
import request from "supertest";
2+
import { describe, test, expect, vi, afterEach } from 'vitest';
3+
import request from 'supertest';
44

55
import { mockTokenPayload } from '../../assets/jwt.ts';
66
import { initWsApp } from '../core/express.ts';
@@ -15,8 +15,7 @@ const wsApp = initWsApp(
1515
() => {},
1616
);
1717

18-
19-
describe("doc", () => {
18+
describe('doc', () => {
2019
const verifyJwtSpy = vi.spyOn(jwt, 'verifyJwt');
2120
const s3FetchSpy = vi.spyOn(s3Extension.configuration, 'fetch');
2221

@@ -25,46 +24,46 @@ describe("doc", () => {
2524
s3FetchSpy.mockClear();
2625
});
2726

28-
test("GET /documents/ with incorrect document format", async () => {
27+
test('GET /documents/ with incorrect document format', async () => {
2928
verifyJwtSpy.mockResolvedValueOnce(mockTokenPayload);
3029

3130
const res = await request(wsApp)
32-
.get("/documents/doc_v1_9999")
33-
.set("Authorization", "Bearer my-valid-token")
31+
.get('/documents/doc_v1_9999')
32+
.set('Authorization', 'Bearer my-valid-token');
3433

3534
expect(verifyJwtSpy).toHaveBeenCalledOnce();
3635

3736
expect(res.status).toBe(422);
3837
expect(res.body).toStrictEqual({
39-
"message": "Validation failed",
40-
"details": {
41-
"name": {
42-
"message": "Document name should start with \"document\"",
43-
"value": "doc_v1_9999",
44-
}
38+
message: 'Validation failed',
39+
details: {
40+
name: {
41+
message: 'Document name should start with "document"',
42+
value: 'doc_v1_9999',
43+
},
4544
},
4645
});
4746
});
4847

49-
test("GET /documents/ with non existing document", async () => {
48+
test('GET /documents/ with non existing document', async () => {
5049
verifyJwtSpy.mockResolvedValueOnce(mockTokenPayload);
5150
s3FetchSpy.mockResolvedValueOnce(null);
5251

5352
const res = await request(wsApp)
54-
.get("/documents/document_v1_8888")
55-
.set("Authorization", "Bearer my-valid-token")
53+
.get('/documents/document_v1_8888')
54+
.set('Authorization', 'Bearer my-valid-token');
5655

5756
expect(verifyJwtSpy).toHaveBeenCalledOnce();
5857
expect(s3FetchSpy).toHaveBeenCalledOnce();
5958

6059
expect(res.status).toBe(404);
6160
expect(res.body).toStrictEqual({
62-
"details": "Document not found",
63-
"message": "Resource not found",
61+
details: 'Document not found',
62+
message: 'Resource not found',
6463
});
6564
});
6665

67-
test("GET /doc/ with existing document", async () => {
66+
test('GET /doc/ with existing document', async () => {
6867
verifyJwtSpy.mockResolvedValueOnce(mockTokenPayload);
6968

7069
const doc = new Y.Doc();
@@ -73,8 +72,8 @@ describe("doc", () => {
7372
s3FetchSpy.mockResolvedValueOnce(binaryData);
7473

7574
const res = await request(wsApp)
76-
.get("/documents/document_v1_9999")
77-
.set("Authorization", "Bearer my-valid-token")
75+
.get('/documents/document_v1_9999')
76+
.set('Authorization', 'Bearer my-valid-token');
7877

7978
expect(verifyJwtSpy).toHaveBeenCalledOnce();
8079
expect(s3FetchSpy).toHaveBeenCalledOnce();
@@ -90,12 +89,12 @@ describe("doc", () => {
9089
},
9190
// NOTE: Added by default
9291
summary_satellite_sensors: {
93-
"children": [
92+
children: [
9493
{
95-
type: "p",
94+
type: 'p',
9695
children: [
9796
{
98-
"text": "",
97+
text: '',
9998
},
10099
],
101100
},

0 commit comments

Comments
 (0)