Skip to content

Commit

Permalink
chore: fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco Buceta <frbuceta@gmail.com>
  • Loading branch information
frbuceta committed Apr 25, 2022
1 parent 05ec8d1 commit 490dd76
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 63 deletions.
8 changes: 4 additions & 4 deletions extensions/socketio/src/socketio.server.ts
Expand Up @@ -152,9 +152,9 @@ export class SocketIoServer extends Context {
this.app.bind(getNamespaceKeyForName(meta.name)).to(nsp);
}

nsp.on('connection', socket =>
this.createSocketHandler(controllerClass)(socket),
);
nsp.on('connection', async socket => {
await this.createSocketHandler(controllerClass)(socket);
});
return nsp;
}

Expand All @@ -164,7 +164,7 @@ export class SocketIoServer extends Context {
*/
private createSocketHandler(
controllerClass: Constructor<object>,
): (socket: Socket) => void {
): (socket: Socket) => Promise<void> {
return async socket => {
debug(
'SocketIo connected: id=%s namespace=%s',
Expand Down
Expand Up @@ -52,7 +52,7 @@ describe('booter-lb3app', () => {
},
});

const schemas = (spec.components ?? {}).schemas ?? {};
const schemas = spec.components?.schemas ?? {};
expect(schemas._new_CoffeeShop)
.to.have.property('properties')
.eql({
Expand All @@ -68,7 +68,7 @@ describe('booter-lb3app', () => {

it('includes the target model as a property of the source model in a relation', async () => {
const spec = await app.restServer.getApiSpec();
const schemas = (spec.components ?? {}).schemas ?? {};
const schemas = spec.components?.schemas ?? {};

expect(schemas.CoffeeShop)
.to.have.property('properties')
Expand Down
3 changes: 3 additions & 0 deletions packages/context/src/__tests__/unit/resolver.unit.ts
Expand Up @@ -631,6 +631,7 @@ describe('method injection', () => {
let savedInstance;
class TestClass {
test(@inject('foo') foo: string) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
savedInstance = this;
return `hello ${foo}`;
}
Expand All @@ -647,6 +648,7 @@ describe('method injection', () => {
bar: string;

test(@inject('foo') foo: string) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
savedInstance = this;
this.bar = foo;
return `hello ${foo}`;
Expand Down Expand Up @@ -724,6 +726,7 @@ describe('async method injection', () => {
bar: string;

test(@inject('foo') foo: string) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
savedInstance = this;
this.bar = foo;
return Promise.resolve(`hello ${foo}`);
Expand Down
29 changes: 9 additions & 20 deletions packages/eslint-config/eslintrc.js
Expand Up @@ -162,20 +162,14 @@ module.exports = {
{
selector: 'variable',
format: null,
filter: {
regex: '^_$',
match: true,
},
filter: '^_$',
},

// For mixin functions
{
selector: 'function',
format: ['PascalCase'],
filter: {
regex: 'Mixin$',
match: true,
},
filter: 'Mixin$',
},

{
Expand All @@ -184,18 +178,6 @@ module.exports = {
leadingUnderscore: 'allow',
},

// For members such as `Content-Type` or `application/json` or `200`
{
selector: 'memberLike',
format: null,
filter: {
// you can expand this regex as you find more cases that require
// quoting that you want to allow
regex: '[0-9-/ ]',
match: true,
},
},

// For enum members
{
selector: 'enumMember',
Expand Down Expand Up @@ -243,6 +225,13 @@ module.exports = {
selector: 'typeLike',
format: ['PascalCase'],
},

{
selector: 'objectLiteralProperty',
format: null,
// filter: '^([2-5]{1}[0-9]{2})$|[-/ ]',
modifiers: ['requiresQuotes'],
},
],
},

Expand Down
50 changes: 31 additions & 19 deletions packages/express/src/__tests__/acceptance/test-helpers.ts
Expand Up @@ -11,13 +11,22 @@ import {
} from '@loopback/core';
import {Client, givenHttpServerConfig, supertest} from '@loopback/testlab';
import bodyParser from 'body-parser';
import {NextFunction, Request, Response} from 'express';
import {ExpressApplication} from '../../express.application';
import {ExpressRequestHandler} from '../../types';
import {SpyAction, SpyConfig} from '../fixtures/spy-config';
import spyFactory from '../fixtures/spy.middleware';
export const spy = spyFactory;

export {default as spy} from '../fixtures/spy.middleware';
export {SpyConfig} from '../fixtures/spy-config';

function runAsyncWrapper(
callback: (req: Request, res: Response, next: NextFunction) => Promise<void>,
): ExpressRequestHandler {
return function (req: Request, res: Response, next: NextFunction) {
callback(req, res, next).catch(next);
};
}

export type TestFunction = (
spyBinding: Binding<unknown>,
path?: string,
Expand Down Expand Up @@ -62,23 +71,26 @@ export class TestHelper {
}
}
const binding = this.app.controller(MyController);
const handler: ExpressRequestHandler = async (req, res, next) => {
try {
const controller = await this.app.get<MyController>(binding.key);
const proxy = createProxyWithInterceptors(
controller,
this.app.expressServer.getMiddlewareContext(req),
undefined,
{
type: 'route',
value: controller,
},
);
res.send(await proxy.hello(req.body));
} catch (err) {
next(err);
}
};

const handler: ExpressRequestHandler = runAsyncWrapper(
async (req, res, next) => {
try {
const controller = await this.app.get<MyController>(binding.key);
const proxy = createProxyWithInterceptors(
controller,
this.app.expressServer.getMiddlewareContext(req),
undefined,
{
type: 'route',
value: controller,
},
);
res.send(await proxy.hello(req.body));
} catch (err) {
next(err);
}
},
);
this.app.expressServer.expressApp.post('/hello', handler);
this.app.expressServer.expressApp.post('/greet', handler);
}
Expand Down
25 changes: 16 additions & 9 deletions packages/express/src/middleware.ts
Expand Up @@ -353,16 +353,23 @@ export function invokeExpressMiddleware(
* @param ctx - Context object to discover registered middleware
*/
export function toExpressMiddleware(ctx: Context): ExpressRequestHandler {
return async (req, res, next) => {
return (req, res, next) => {
const middlewareCtx = new MiddlewareContext(req, res, ctx);

try {
const result = await invokeMiddleware(middlewareCtx);
if (result !== res) {
next();
}
} catch (err) {
next(err);
}
new Promise((resolve, reject) => {
// eslint-disable-next-line no-void
void (async () => {
try {
const result = await invokeMiddleware(middlewareCtx);
resolve(result);
} catch (err) {
reject(err);
}
})();
})
.then(result => {
if (result !== res) next();
})
.catch(next);
};
}
2 changes: 1 addition & 1 deletion packages/monorepo/lib/config-lerna-scopes.js
Expand Up @@ -14,7 +14,7 @@ const {getPackages, runMain} = require('./script-util');

module.exports = {
rules: {
// https://github.com/marionebl/commitlint/blob/master/docs/reference-rules.md
// eslint-disable-next-line @typescript-eslint/naming-convention
'scope-enum': async ctx => [2, 'always', await getPackageNames(ctx)],
},
};
Expand Down
Expand Up @@ -313,7 +313,7 @@ describe('controller spec', () => {
$ref: '#/components/schemas/Todo',
});

const globalSchemas = (spec.components ?? {}).schemas;
const globalSchemas = spec.components?.schemas;
expect(globalSchemas).to.deepEqual({
Todo: {
title: 'Todo',
Expand Down Expand Up @@ -362,7 +362,7 @@ describe('controller spec', () => {
$ref: '#/definitions/Todo',
});

const globalSchemas = (spec.components ?? {}).schemas;
const globalSchemas = spec.components?.schemas;
expect(globalSchemas).to.deepEqual({
Todo: {
title: 'Todo',
Expand Down Expand Up @@ -462,7 +462,7 @@ describe('controller spec', () => {
}

const spec = getControllerSpec(MyController);
const globalSchemas = (spec.components ?? {}).schemas;
const globalSchemas = spec.components?.schemas;
expect(globalSchemas).to.be.undefined();
});

Expand Down Expand Up @@ -533,7 +533,7 @@ describe('controller spec', () => {
},
});

const globalSchemas = (spec.components ?? {}).schemas;
const globalSchemas = spec.components?.schemas;
expect(globalSchemas).to.deepEqual({
Todo: {
title: 'Todo',
Expand Down Expand Up @@ -593,7 +593,7 @@ describe('controller spec', () => {
$ref: '#/components/schemas/Todo',
});

const globalSchemas = (spec.components ?? {}).schemas;
const globalSchemas = spec.components?.schemas;
expect(globalSchemas).to.deepEqual({
Todo: {
title: 'Todo',
Expand Down Expand Up @@ -861,7 +861,7 @@ describe('controller spec', () => {
$ref: '#/components/schemas/MyModel',
});

const globalSchemas = (spec.components ?? {}).schemas;
const globalSchemas = spec.components?.schemas;
expect(globalSchemas).to.deepEqual({
MyModel: {
title: 'MyModel',
Expand Down
2 changes: 1 addition & 1 deletion packages/repository-tests/src/helpers.repository-tests.ts
Expand Up @@ -37,7 +37,7 @@ export function withCrudCtx(
*/
export const deleteAllModelsInDefaultDataSource = withCrudCtx(ctx => {
ctx.dataSource.deleteAllModels();
});
}) as Mocha.Func;

/**
* A union type between string and number to use since MongoDB and MySQL use
Expand Down
2 changes: 1 addition & 1 deletion packages/rest-crud/src/crud-rest.controller.ts
Expand Up @@ -280,7 +280,7 @@ function getIdSchema<T extends Entity>(
const modelSchema = jsonToSchemaObject(
getJsonSchema(modelCtor),
) as SchemaObject;
return (modelSchema.properties ?? {})[idProp] as SchemaObject;
return modelSchema.properties?.[idProp] as SchemaObject;
}

// Temporary implementation of a short-hand version of `@requestBody`
Expand Down

0 comments on commit 490dd76

Please sign in to comment.