diff --git a/.prettierrc b/.prettierrc index a20502b7f06..7cac555b0c5 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,4 +1,5 @@ { "singleQuote": true, + "arrowParens": "avoid", "trailingComma": "all" } diff --git a/integration/hello-world/e2e/exceptions.spec.ts b/integration/hello-world/e2e/exceptions.spec.ts index 5fee5f701cd..7cf8223abd8 100644 --- a/integration/hello-world/e2e/exceptions.spec.ts +++ b/integration/hello-world/e2e/exceptions.spec.ts @@ -18,25 +18,19 @@ describe('Error messages', () => { }); it(`/GET`, () => { - return request(server) - .get('/sync') - .expect(HttpStatus.BAD_REQUEST) - .expect({ - statusCode: 400, - error: 'Bad Request', - message: 'Integration test', - }); + return request(server).get('/sync').expect(HttpStatus.BAD_REQUEST).expect({ + statusCode: 400, + error: 'Bad Request', + message: 'Integration test', + }); }); it(`/GET (Promise/async)`, () => { - return request(server) - .get('/async') - .expect(HttpStatus.BAD_REQUEST) - .expect({ - statusCode: 400, - error: 'Bad Request', - message: 'Integration test', - }); + return request(server).get('/async').expect(HttpStatus.BAD_REQUEST).expect({ + statusCode: 400, + error: 'Bad Request', + message: 'Integration test', + }); }); afterEach(async () => { diff --git a/integration/hello-world/e2e/exclude-middleware-fastify.spec.ts b/integration/hello-world/e2e/exclude-middleware-fastify.spec.ts index b8507566b17..09a324dd78c 100644 --- a/integration/hello-world/e2e/exclude-middleware-fastify.spec.ts +++ b/integration/hello-world/e2e/exclude-middleware-fastify.spec.ts @@ -78,16 +78,11 @@ describe('Exclude middleware (fastify)', () => { ).createNestApplication(new FastifyAdapter()); await app.init(); - await app - .getHttpAdapter() - .getInstance() - .ready(); + await app.getHttpAdapter().getInstance().ready(); }); it(`should exclude "/test" endpoint`, () => { - return request(app.getHttpServer()) - .get('/test') - .expect(200, RETURN_VALUE); + return request(app.getHttpServer()).get('/test').expect(200, RETURN_VALUE); }); it(`should not exclude "/test2" endpoint`, () => { diff --git a/integration/hello-world/e2e/exclude-middleware.spec.ts b/integration/hello-world/e2e/exclude-middleware.spec.ts index c544bbc5760..0b0fe2d7413 100644 --- a/integration/hello-world/e2e/exclude-middleware.spec.ts +++ b/integration/hello-world/e2e/exclude-middleware.spec.ts @@ -77,9 +77,7 @@ describe('Exclude middleware', () => { }); it(`should exclude "/test" endpoint`, () => { - return request(app.getHttpServer()) - .get('/test') - .expect(200, RETURN_VALUE); + return request(app.getHttpServer()).get('/test').expect(200, RETURN_VALUE); }); it(`should not exclude "/test2" endpoint`, () => { diff --git a/integration/hello-world/e2e/express-instance.spec.ts b/integration/hello-world/e2e/express-instance.spec.ts index 790d9305206..9774487a245 100644 --- a/integration/hello-world/e2e/express-instance.spec.ts +++ b/integration/hello-world/e2e/express-instance.spec.ts @@ -20,10 +20,7 @@ describe('Hello world (express instance)', () => { }); it(`/GET`, () => { - return request(server) - .get('/hello') - .expect(200) - .expect('Hello world!'); + return request(server).get('/hello').expect(200).expect('Hello world!'); }); it(`/GET (Promise/async)`, () => { @@ -41,14 +38,11 @@ describe('Hello world (express instance)', () => { }); it(`/GET { host: ":tenant.example.com" } not matched`, () => { - return request(server) - .get('/host') - .expect(404) - .expect({ - statusCode: 404, - error: 'Not Found', - message: 'Cannot GET /host', - }); + return request(server).get('/host').expect(404).expect({ + statusCode: 404, + error: 'Not Found', + message: 'Cannot GET /host', + }); }); afterEach(async () => { diff --git a/integration/hello-world/e2e/express-multiple.spec.ts b/integration/hello-world/e2e/express-multiple.spec.ts index 62516e0185a..431e896b7d8 100644 --- a/integration/hello-world/e2e/express-multiple.spec.ts +++ b/integration/hello-world/e2e/express-multiple.spec.ts @@ -29,10 +29,7 @@ describe('Hello world (express instance with multiple applications)', () => { }); it(`/GET`, () => { - return request(server) - .get('/hello') - .expect(200) - .expect('Hello world!'); + return request(server).get('/hello').expect(200).expect('Hello world!'); }); it(`/GET (app2)`, () => { diff --git a/integration/hello-world/e2e/guards.spec.ts b/integration/hello-world/e2e/guards.spec.ts index 530ad923b66..08e372e0067 100644 --- a/integration/hello-world/e2e/guards.spec.ts +++ b/integration/hello-world/e2e/guards.spec.ts @@ -37,8 +37,6 @@ describe('Guards', () => { app = (await createTestModule(new AuthGuard())).createNestApplication(); await app.init(); - return request(app.getHttpServer()) - .get('/hello') - .expect(401); + return request(app.getHttpServer()).get('/hello').expect(401); }); }); diff --git a/integration/hello-world/e2e/interceptors.spec.ts b/integration/hello-world/e2e/interceptors.spec.ts index 30d8ce57017..11222c51443 100644 --- a/integration/hello-world/e2e/interceptors.spec.ts +++ b/integration/hello-world/e2e/interceptors.spec.ts @@ -77,9 +77,7 @@ describe('Interceptors', () => { ).createNestApplication(); await app.init(); - return request(app.getHttpServer()) - .get('/hello') - .expect(200, RETURN_VALUE); + return request(app.getHttpServer()).get('/hello').expect(200, RETURN_VALUE); }); it(`should map response`, async () => { diff --git a/integration/hello-world/e2e/local-pipes.spec.ts b/integration/hello-world/e2e/local-pipes.spec.ts index bf403170ee1..5bc4a66d8cd 100644 --- a/integration/hello-world/e2e/local-pipes.spec.ts +++ b/integration/hello-world/e2e/local-pipes.spec.ts @@ -18,12 +18,9 @@ describe('Hello world (default adapter)', () => { }); it(`host=example.com should execute locally injected pipe by HelloController`, () => { - return request(server) - .get('/hello/local-pipe/1') - .expect(200) - .expect({ - id: '1', - }); + return request(server).get('/hello/local-pipe/1').expect(200).expect({ + id: '1', + }); }); it(`host=host.example.com should execute locally injected pipe by HostController`, () => { @@ -39,14 +36,11 @@ describe('Hello world (default adapter)', () => { }); it(`should return 404 for mismatched host`, () => { - return request(server) - .get('/host/local-pipe/1') - .expect(404) - .expect({ - error: 'Not Found', - message: 'Cannot GET /host/local-pipe/1', - statusCode: 404, - }); + return request(server).get('/host/local-pipe/1').expect(404).expect({ + error: 'Not Found', + message: 'Cannot GET /host/local-pipe/1', + statusCode: 404, + }); }); afterEach(async () => { diff --git a/integration/hello-world/e2e/middleware-class.spec.ts b/integration/hello-world/e2e/middleware-class.spec.ts index 2ce8aade848..8a573990121 100644 --- a/integration/hello-world/e2e/middleware-class.spec.ts +++ b/integration/hello-world/e2e/middleware-class.spec.ts @@ -51,9 +51,7 @@ describe('Middleware (class)', () => { }); it(`forRoutes(*)`, () => { - return request(app.getHttpServer()) - .get('/hello') - .expect(200, RETURN_VALUE); + return request(app.getHttpServer()).get('/hello').expect(200, RETURN_VALUE); }); afterEach(async () => { diff --git a/integration/hello-world/e2e/middleware.spec.ts b/integration/hello-world/e2e/middleware.spec.ts index baa2595f313..a7fc00fa67d 100644 --- a/integration/hello-world/e2e/middleware.spec.ts +++ b/integration/hello-world/e2e/middleware.spec.ts @@ -57,15 +57,11 @@ describe('Middleware', () => { }); it(`forRoutes(*)`, () => { - return request(app.getHttpServer()) - .get('/hello') - .expect(200, RETURN_VALUE); + return request(app.getHttpServer()).get('/hello').expect(200, RETURN_VALUE); }); it(`forRoutes(TestController)`, () => { - return request(app.getHttpServer()) - .get('/test') - .expect(200, SCOPED_VALUE); + return request(app.getHttpServer()).get('/test').expect(200, SCOPED_VALUE); }); it(`forRoutes(tests/*)`, () => { diff --git a/integration/microservices/e2e/broadcast-mqtt.spec.ts b/integration/microservices/e2e/broadcast-mqtt.spec.ts index 496259fbb26..632fb19a930 100644 --- a/integration/microservices/e2e/broadcast-mqtt.spec.ts +++ b/integration/microservices/e2e/broadcast-mqtt.spec.ts @@ -33,9 +33,7 @@ describe('MQTT transport', () => { }); it(`Broadcast (2 subscribers)`, () => { - return request(server) - .get('/broadcast') - .expect(200, '2'); + return request(server).get('/broadcast').expect(200, '2'); }); afterEach(async () => { diff --git a/integration/microservices/e2e/broadcast-nats.spec.ts b/integration/microservices/e2e/broadcast-nats.spec.ts index 2570f928bcb..5c8e632c200 100644 --- a/integration/microservices/e2e/broadcast-nats.spec.ts +++ b/integration/microservices/e2e/broadcast-nats.spec.ts @@ -33,9 +33,7 @@ describe('NATS transport', () => { }); it(`Broadcast (2 subscribers)`, () => { - return request(server) - .get('/broadcast') - .expect(200, '2'); + return request(server).get('/broadcast').expect(200, '2'); }); afterEach(async () => { diff --git a/integration/microservices/e2e/broadcast-redis.spec.ts b/integration/microservices/e2e/broadcast-redis.spec.ts index 1a14e55296e..c4c40d9fa81 100644 --- a/integration/microservices/e2e/broadcast-redis.spec.ts +++ b/integration/microservices/e2e/broadcast-redis.spec.ts @@ -33,9 +33,7 @@ describe('REDIS transport', () => { }); it(`Broadcast (2 subscribers)`, () => { - return request(server) - .get('/broadcast') - .expect(200, '2'); + return request(server).get('/broadcast').expect(200, '2'); }); afterEach(async () => { diff --git a/integration/microservices/e2e/orders-grpc.spec.ts b/integration/microservices/e2e/orders-grpc.spec.ts index eeb1a52dada..e0171948352 100644 --- a/integration/microservices/e2e/orders-grpc.spec.ts +++ b/integration/microservices/e2e/orders-grpc.spec.ts @@ -129,11 +129,7 @@ describe('Advanced GRPC transport', () => { callHandler.on('error', (err: any) => { // We want to fail only on real errors while Cancellation error // is expected - if ( - String(err) - .toLowerCase() - .indexOf('cancelled') === -1 - ) { + if (String(err).toLowerCase().indexOf('cancelled') === -1) { fail('gRPC Stream error happened, error: ' + err); } }); @@ -165,11 +161,7 @@ describe('Advanced GRPC transport', () => { callHandler.on('error', (err: any) => { // We want to fail only on real errors while Cancellation error // is expected - if ( - String(err) - .toLowerCase() - .indexOf('cancelled') === -1 - ) { + if (String(err).toLowerCase().indexOf('cancelled') === -1) { fail('gRPC Stream error happened, error: ' + err); } }); diff --git a/integration/microservices/e2e/sum-grpc.spec.ts b/integration/microservices/e2e/sum-grpc.spec.ts index 0f649bf80c8..14084b54ca3 100644 --- a/integration/microservices/e2e/sum-grpc.spec.ts +++ b/integration/microservices/e2e/sum-grpc.spec.ts @@ -63,11 +63,7 @@ describe('GRPC transport', () => { callHandler.on('error', (err: any) => { // We want to fail only on real errors while Cancellation error // is expected - if ( - String(err) - .toLowerCase() - .indexOf('cancelled') === -1 - ) { + if (String(err).toLowerCase().indexOf('cancelled') === -1) { fail('gRPC Stream error happened, error: ' + err); } }); @@ -89,11 +85,7 @@ describe('GRPC transport', () => { callHandler.on('error', (err: any) => { // We want to fail only on real errors while Cancellation error // is expected - if ( - String(err) - .toLowerCase() - .indexOf('cancelled') === -1 - ) { + if (String(err).toLowerCase().indexOf('cancelled') === -1) { fail('gRPC Stream error happened, error: ' + err); } }); diff --git a/integration/microservices/e2e/sum-kafka.spec.ts b/integration/microservices/e2e/sum-kafka.spec.ts index 671d67c6e59..b98440e37a9 100644 --- a/integration/microservices/e2e/sum-kafka.spec.ts +++ b/integration/microservices/e2e/sum-kafka.spec.ts @@ -106,17 +106,11 @@ describe('Kafka transport', () => { user: newUser, }; it(`/POST (sync command create user)`, () => { - return request(server) - .post('/user') - .send(userDto) - .expect(200); + return request(server).post('/user').send(userDto).expect(200); }); it(`/POST (sync command create business`, () => { - return request(server) - .post('/business') - .send(businessDto) - .expect(200); + return request(server).post('/business').send(businessDto).expect(200); }); it(`/POST (sync command create user) Concurrency Test`, async () => { @@ -124,12 +118,7 @@ describe('Kafka transport', () => { for (let concurrencyKey = 0; concurrencyKey < 100; concurrencyKey++) { const innerUserDto = JSON.parse(JSON.stringify(userDto)); innerUserDto.name += `+${concurrencyKey}`; - promises.push( - request(server) - .post('/user') - .send(userDto) - .expect(200), - ); + promises.push(request(server).post('/user').send(userDto).expect(200)); } await Promise.all(promises); }); diff --git a/integration/microservices/e2e/sum-mqtt.spec.ts b/integration/microservices/e2e/sum-mqtt.spec.ts index dd02be32026..0c305664084 100644 --- a/integration/microservices/e2e/sum-mqtt.spec.ts +++ b/integration/microservices/e2e/sum-mqtt.spec.ts @@ -49,7 +49,7 @@ describe('MQTT transport', () => { .expect(200, '15'); }); - it(`/POST (concurrent)`, function() { + it(`/POST (concurrent)`, function () { return request(server) .post('/concurrent') .send([ diff --git a/integration/microservices/e2e/sum-nats.spec.ts b/integration/microservices/e2e/sum-nats.spec.ts index 89452a953f0..eff4ce88ad4 100644 --- a/integration/microservices/e2e/sum-nats.spec.ts +++ b/integration/microservices/e2e/sum-nats.spec.ts @@ -75,12 +75,10 @@ describe('NATS transport', () => { }); it(`/GET (exception)`, () => { - return request(server) - .get('/exception') - .expect(200, { - message: 'test', - status: 'error', - }); + return request(server).get('/exception').expect(200, { + message: 'test', + status: 'error', + }); }); it(`/POST (event notification)`, done => { diff --git a/integration/microservices/e2e/sum-redis.spec.ts b/integration/microservices/e2e/sum-redis.spec.ts index c3e54b5862b..7f0bc8d1d62 100644 --- a/integration/microservices/e2e/sum-redis.spec.ts +++ b/integration/microservices/e2e/sum-redis.spec.ts @@ -49,7 +49,7 @@ describe('REDIS transport', () => { .expect(200, '15'); }); - it(`/POST (concurrent)`, function() { + it(`/POST (concurrent)`, function () { this.retries(10); return request(server) diff --git a/integration/microservices/e2e/sum-rpc.spec.ts b/integration/microservices/e2e/sum-rpc.spec.ts index a58cb69cec2..0bead64a8c5 100644 --- a/integration/microservices/e2e/sum-rpc.spec.ts +++ b/integration/microservices/e2e/sum-rpc.spec.ts @@ -76,9 +76,7 @@ describe('RPC transport', () => { }); it(`/POST (pattern not found)`, () => { - return request(server) - .post('/?command=test') - .expect(500); + return request(server).post('/?command=test').expect(500); }); it(`/POST (event notification)`, done => { diff --git a/integration/websockets/e2e/ws-gateway.spec.ts b/integration/websockets/e2e/ws-gateway.spec.ts index f44a53ae382..1980998c638 100644 --- a/integration/websockets/e2e/ws-gateway.spec.ts +++ b/integration/websockets/e2e/ws-gateway.spec.ts @@ -65,7 +65,7 @@ describe('WebSocketGateway (WsAdapter)', () => { ); }); - it(`should support 2 different gateways`, async function() { + it(`should support 2 different gateways`, async function () { this.retries(10); app = await createNestApp(ApplicationGateway, CoreGateway); diff --git a/packages/core/errors/exceptions/unknown-element.exception.ts b/packages/core/errors/exceptions/unknown-element.exception.ts index 0a7c83c60a5..09c82e8f05e 100644 --- a/packages/core/errors/exceptions/unknown-element.exception.ts +++ b/packages/core/errors/exceptions/unknown-element.exception.ts @@ -3,8 +3,9 @@ import { RuntimeException } from './runtime.exception'; export class UnknownElementException extends RuntimeException { constructor(name?: string) { super( - `Nest could not find ${name || - 'given'} element (this provider does not exist in the current context)`, + `Nest could not find ${ + name || 'given' + } element (this provider does not exist in the current context)`, ); } } diff --git a/packages/core/errors/messages.ts b/packages/core/errors/messages.ts index fb5d71a8c3b..9ed3a17dd5e 100644 --- a/packages/core/errors/messages.ts +++ b/packages/core/errors/messages.ts @@ -109,8 +109,9 @@ export const INVALID_CLASS_SCOPE_MESSAGE = ( text: TemplateStringsArray, name: string | undefined, ) => - `${name || - 'This class'} is marked as a scoped provider. Request and transient-scoped providers can't be used in combination with "get()" method. Please, use "resolve()" instead.`; + `${ + name || 'This class' + } is marked as a scoped provider. Request and transient-scoped providers can't be used in combination with "get()" method. Please, use "resolve()" instead.`; export const INVALID_MIDDLEWARE_CONFIGURATION = `An invalid middleware configuration has been passed inside the module 'configure()' method.`; export const UNKNOWN_REQUEST_MAPPING = `An invalid controller has been detected. Perhaps, one of your controllers is missing @Controller() decorator.`; diff --git a/packages/core/nest-application-context.ts b/packages/core/nest-application-context.ts index d3370551f45..03d666a176d 100644 --- a/packages/core/nest-application-context.ts +++ b/packages/core/nest-application-context.ts @@ -138,12 +138,7 @@ export class NestApplicationContext implements INestApplicationContext { } signals = signals - .map((signal: string) => - signal - .toString() - .toUpperCase() - .trim(), - ) + .map((signal: string) => signal.toString().toUpperCase().trim()) // filter out the signals which is already listening to .filter(signal => !this.activeShutdownSignals.includes(signal)); diff --git a/packages/core/scanner.ts b/packages/core/scanner.ts index c1c582157a4..db8f16250fb 100644 --- a/packages/core/scanner.ts +++ b/packages/core/scanner.ts @@ -313,7 +313,9 @@ export class DependenciesScanner { if (!providersKeys.includes(type as string)) { return this.container.addProvider(provider as any, token); } - const providerToken = `${type as string} (UUID: ${randomStringGenerator()})`; + const providerToken = `${ + type as string + } (UUID: ${randomStringGenerator()})`; let scope = (provider as ClassProvider | FactoryProvider).scope; if (isNil(scope) && (provider as ClassProvider).useClass) { diff --git a/packages/microservices/server/server-grpc.ts b/packages/microservices/server/server-grpc.ts index ce25a8e84c4..64ba6676b2b 100644 --- a/packages/microservices/server/server-grpc.ts +++ b/packages/microservices/server/server-grpc.ts @@ -240,9 +240,7 @@ export class ServerGrpc extends Server implements CustomTransportStrategy { call.on('data', (m: any) => req.next(m)); call.on('error', (e: any) => { // Check if error means that stream ended on other end - const isCancelledError = String(e) - .toLowerCase() - .indexOf('cancelled'); + const isCancelledError = String(e).toLowerCase().indexOf('cancelled'); if (isCancelledError) { call.end(); diff --git a/packages/microservices/test/client/client-proxy.spec.ts b/packages/microservices/test/client/client-proxy.spec.ts index 61b2ed7a159..6ebd0968a44 100644 --- a/packages/microservices/test/client/client-proxy.spec.ts +++ b/packages/microservices/test/client/client-proxy.spec.ts @@ -16,7 +16,7 @@ class TestClientProxy extends ClientProxy { public async close() {} } -describe('ClientProxy', function() { +describe('ClientProxy', function () { this.retries(10); let client: TestClientProxy; diff --git a/packages/microservices/test/client/client-rmq.spec.ts b/packages/microservices/test/client/client-rmq.spec.ts index d0f93ff6a42..e49036c3bce 100644 --- a/packages/microservices/test/client/client-rmq.spec.ts +++ b/packages/microservices/test/client/client-rmq.spec.ts @@ -4,7 +4,7 @@ import { empty } from 'rxjs'; import * as sinon from 'sinon'; import { ClientRMQ } from '../../client/client-rmq'; -describe('ClientRMQ', function() { +describe('ClientRMQ', function () { this.retries(10); let client: ClientRMQ; diff --git a/sample/01-cats-app/e2e/cats/cats.e2e-spec.ts b/sample/01-cats-app/e2e/cats/cats.e2e-spec.ts index 4ebed219b30..7ec513b241e 100644 --- a/sample/01-cats-app/e2e/cats/cats.e2e-spec.ts +++ b/sample/01-cats-app/e2e/cats/cats.e2e-spec.ts @@ -23,12 +23,9 @@ describe('Cats', () => { }); it(`/GET cats`, () => { - return request(app.getHttpServer()) - .get('/cats') - .expect(200) - .expect({ - data: catsService.findAll(), - }); + return request(app.getHttpServer()).get('/cats').expect(200).expect({ + data: catsService.findAll(), + }); }); afterAll(async () => { diff --git a/sample/12-graphql-schema-first/src/common/directives/upper-case.directive.ts b/sample/12-graphql-schema-first/src/common/directives/upper-case.directive.ts index 65133079604..62640c1ef9f 100644 --- a/sample/12-graphql-schema-first/src/common/directives/upper-case.directive.ts +++ b/sample/12-graphql-schema-first/src/common/directives/upper-case.directive.ts @@ -4,7 +4,7 @@ import { defaultFieldResolver, GraphQLField } from 'graphql'; export class UpperCaseDirective extends SchemaDirectiveVisitor { visitFieldDefinition(field: GraphQLField) { const { resolve = defaultFieldResolver } = field; - field.resolve = async function(...args) { + field.resolve = async function (...args) { const result = await resolve.apply(this, args); if (typeof result === 'string') { return result.toUpperCase(); diff --git a/sample/23-graphql-code-first/src/common/directives/upper-case.directive.ts b/sample/23-graphql-code-first/src/common/directives/upper-case.directive.ts index 65133079604..62640c1ef9f 100644 --- a/sample/23-graphql-code-first/src/common/directives/upper-case.directive.ts +++ b/sample/23-graphql-code-first/src/common/directives/upper-case.directive.ts @@ -4,7 +4,7 @@ import { defaultFieldResolver, GraphQLField } from 'graphql'; export class UpperCaseDirective extends SchemaDirectiveVisitor { visitFieldDefinition(field: GraphQLField) { const { resolve = defaultFieldResolver } = field; - field.resolve = async function(...args) { + field.resolve = async function (...args) { const result = await resolve.apply(this, args); if (typeof result === 'string') { return result.toUpperCase();