Skip to content

Commit 68dccee

Browse files
chore: update line length to 120 (VF-3310) (#86)
- chore: update config - refactor: update line numbers Co-authored-by: Daniel Liu <[email protected]>
1 parent 1dabab1 commit 68dccee

File tree

10 files changed

+62
-14
lines changed

10 files changed

+62
-14
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ insert_final_newline = false
2727

2828
[*.js]
2929
trim_trailing_whitespace = false
30-
max_line_length = 150
30+
max_line_length = 120

.eslintrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ module.exports = {
55
files: ['config/**/*', 'test/**/*'],
66
extends: ['@voiceflow/eslint-config/utility', '@voiceflow/eslint-config/mocha'],
77
rules: {
8+
'max-len': [
9+
'error',
10+
{
11+
code: 120,
12+
ignoreUrls: true,
13+
ignoreStrings: true,
14+
ignoreTemplateLiterals: true,
15+
ignoreRegExpLiterals: true,
16+
},
17+
],
818
// off
919
'no-unused-expressions': 'off',
1020
},

.prettierrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
...require("@voiceflow/prettier-config"),
3+
printWidth: 120,
4+
};

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"ioredis": "^4.28.5",
8585
"jszip": "^3.7.1"
8686
},
87-
"prettier": "@voiceflow/prettier-config",
8887
"repository": {
8988
"type": "git",
9089
"url": "git+https://github.com/voiceflow/backend-utils.git"

src/common/zip/reader.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ export class ZipReader {
6464
});
6565
}
6666

67-
private async *getFilesRecursively(zip: JSZip, config: ZipGetFilesOptions, currentDepth = 0): AsyncGenerator<ZipEntry> {
67+
private async *getFilesRecursively(
68+
zip: JSZip,
69+
config: ZipGetFilesOptions,
70+
currentDepth = 0
71+
): AsyncGenerator<ZipEntry> {
6872
const objects = zip.filter((_, file) => minimatch(file.name, config.path));
6973

7074
let fileCount = 0;

src/fixtureGenerator.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ const createFixture = <T extends ServiceManager<any, any>>(serviceManager: T): T
2727
middlewares: _.mapValues(middlewares, (service) =>
2828
_.mapValues(service, (method) => {
2929
if (method.callback) {
30-
const callbackStub: sinon.SinonStubStatic & { callback?: boolean } = sinon.stub().returns(sinon.stub().callsArg(2));
30+
const callbackStub: sinon.SinonStubStatic & { callback?: boolean } = sinon
31+
.stub()
32+
.returns(sinon.stub().callsArg(2));
3133
callbackStub.callback = true;
3234
return callbackStub;
3335
}
3436

35-
const methodStub: sinon.SinonStubStatic & { validations?: Record<string, sinon.SinonStubStatic> } = sinon.stub().callsArg(2);
37+
const methodStub: sinon.SinonStubStatic & {
38+
validations?: Record<string, sinon.SinonStubStatic>;
39+
} = sinon.stub().callsArg(2);
3640
methodStub.validations = _.mapValues(method.validations, () => sinon.stub().callsArg(2));
3741

3842
return [...Object.values(methodStub.validations), methodStub];
@@ -56,7 +60,10 @@ const createFixture = <T extends ServiceManager<any, any>>(serviceManager: T): T
5660
} as unknown) as T;
5761
};
5862

59-
const checkFixture = <T extends ServiceManager<any, any>>(fixture: T, expected: FixtureExpect<T['controllers'], T['middlewares']>): void => {
63+
const checkFixture = <T extends ServiceManager<any, any>>(
64+
fixture: T,
65+
expected: FixtureExpect<T['controllers'], T['middlewares']>
66+
): void => {
6067
const { middlewares, controllers } = fixture;
6168

6269
const validations = {
@@ -78,7 +85,10 @@ const checkFixture = <T extends ServiceManager<any, any>>(fixture: T, expected:
7885
validations.controllers[controller] = {};
7986
}
8087

81-
validations.controllers[controller][method] = _.mapValues(controllerMethod.validations, (stub) => stub.callCount);
88+
validations.controllers[controller][method] = _.mapValues(
89+
controllerMethod.validations,
90+
(stub) => stub.callCount
91+
);
8292
}
8393

8494
controllers[controller][method] = controllerMethod.callCount;
@@ -97,7 +107,9 @@ const checkFixture = <T extends ServiceManager<any, any>>(fixture: T, expected:
97107
Object.keys(middlewares[service]).forEach((method) => {
98108
const expressMiddlewares = middlewares[service][method];
99109
// if no length -> callback middleware -> it's not an array
100-
const middlewareMethod = expressMiddlewares.length ? expressMiddlewares[expressMiddlewares.length - 1] : expressMiddlewares;
110+
const middlewareMethod = expressMiddlewares.length
111+
? expressMiddlewares[expressMiddlewares.length - 1]
112+
: expressMiddlewares;
101113

102114
if (middlewareMethod.validations) {
103115
if (!validations.middlewares[service]) {

src/middlewares/rateLimit.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { RateLimiterRes } from 'rate-limiter-flexible';
44

55
import { AbstractMiddleware, RateLimitConfig } from '../types';
66

7-
export class RateLimitMiddleware<S extends Record<string, any>, C extends RateLimitConfig> extends AbstractMiddleware<S, C> {
7+
export class RateLimitMiddleware<S extends Record<string, any>, C extends RateLimitConfig> extends AbstractMiddleware<
8+
S,
9+
C
10+
> {
811
static throwAuthError(): never {
912
throw new VError('Auth Key Required', VError.HTTP_STATUS.UNAUTHORIZED);
1013
}
@@ -19,7 +22,11 @@ export class RateLimitMiddleware<S extends Record<string, any>, C extends RateLi
1922
return !req.headers.authorization;
2023
}
2124

22-
async consume(res: Response, next: NextFunction, { resource, isPublic }: { resource: string; isPublic?: boolean }): Promise<void> {
25+
async consume(
26+
res: Response,
27+
next: NextFunction,
28+
{ resource, isPublic }: { resource: string; isPublic?: boolean }
29+
): Promise<void> {
2330
const maxPoints = isPublic ? this.config.RATE_LIMITER_POINTS_PUBLIC : this.config.RATE_LIMITER_POINTS_PRIVATE;
2431
const rateLimiterClient = this.services.rateLimitClient[isPublic ? 'public' : 'private'];
2532

src/responseBuilder.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ class ResponseBuilder {
9696
req?: Request & { user?: { id: number } }
9797
): ErrorResponse<T> {
9898
if (error && (error as any).isAxiosError) {
99-
log.error(`@backend-utils:errorResponse - error:axios:${JSON.stringify(ResponseBuilder.getAxiosError(error as AxiosError))}`);
99+
log.error(
100+
`@backend-utils:errorResponse - error:axios:${JSON.stringify(
101+
ResponseBuilder.getAxiosError(error as AxiosError)
102+
)}`
103+
);
100104
}
101105

102106
if (!(error instanceof Error)) {
@@ -198,7 +202,9 @@ class ResponseBuilder {
198202
let output: ErrorResponse<unknown> | ReturnType<typeof ResponseBuilder['okResponse']>;
199203

200204
try {
201-
const data = await (typeof dataPromise === 'function' ? (dataPromise as any)(req, res, nextCheck) : dataPromise);
205+
const data = await (typeof dataPromise === 'function'
206+
? (dataPromise as any)(req, res, nextCheck)
207+
: dataPromise);
202208

203209
output =
204210
data instanceof Error

src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ export abstract class AbstractMiddleware<S extends Record<string, any>, C extend
3030
constructor(public services: S, public config: C) {}
3131
}
3232

33-
export abstract class AbstractManager<S extends Record<string, any>, C extends Record<string, any>, U extends Record<string, any> = {}> {
33+
export abstract class AbstractManager<
34+
S extends Record<string, any>,
35+
C extends Record<string, any>,
36+
U extends Record<string, any> = {}
37+
> {
3438
services: S & U;
3539

3640
constructor(services: S, public config: C) {

tests/middlewares/rateLimit.unit.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ describe('rateLimit middleware unit tests', () => {
8282
const resource = 'version-id';
8383
const res = { setHeader: sinon.stub() };
8484

85-
await expect(service.consume(res as any, next, { isPublic: true, resource })).to.eventually.rejectedWith('Too Many Request');
85+
await expect(service.consume(res as any, next, { isPublic: true, resource })).to.eventually.rejectedWith(
86+
'Too Many Request'
87+
);
8688

8789
expect(services.rateLimitClient.public.consume.args).to.eql([[resource]]);
8890
expect(res.setHeader.args).to.eql([['Retry-After', Math.floor(rateLimiterRes.msBeforeNext / 1000)]]);

0 commit comments

Comments
 (0)