diff --git a/integration/graphql/src/cats/cats.resolvers.ts b/integration/graphql/src/cats/cats.resolvers.ts index 4bdbeebba17..afccc560252 100644 --- a/integration/graphql/src/cats/cats.resolvers.ts +++ b/integration/graphql/src/cats/cats.resolvers.ts @@ -14,7 +14,7 @@ export class CatsResolvers { @Query() @UseGuards(CatsGuard) async getCats() { - return await this.catsService.findAll(); + return this.catsService.findAll(); } @Query('cat') @@ -22,7 +22,7 @@ export class CatsResolvers { @Args('id', ParseIntPipe) id: number, ): Promise { - return await this.catsService.findOneById(id); + return this.catsService.findOneById(id); } @Mutation('createCat') diff --git a/integration/hello-world/e2e/interceptors.spec.ts b/integration/hello-world/e2e/interceptors.spec.ts index a7e1e9a8581..3a0f4399e4b 100644 --- a/integration/hello-world/e2e/interceptors.spec.ts +++ b/integration/hello-world/e2e/interceptors.spec.ts @@ -30,7 +30,7 @@ export class TransformInterceptor { @Injectable() export class StatusInterceptor { - constructor(private statusCode: number) {} + constructor(private readonly statusCode: number) {} intercept(context: ExecutionContext, next: CallHandler) { const ctx = context.switchToHttp(); @@ -42,7 +42,7 @@ export class StatusInterceptor { @Injectable() export class HeaderInterceptor { - constructor(private headers: object) {} + constructor(private readonly headers: object) {} intercept(context: ExecutionContext, next: CallHandler) { const ctx = context.switchToHttp(); diff --git a/integration/hello-world/src/hello/hello.controller.ts b/integration/hello-world/src/hello/hello.controller.ts index 80fd6404195..be715e1471b 100644 --- a/integration/hello-world/src/hello/hello.controller.ts +++ b/integration/hello-world/src/hello/hello.controller.ts @@ -15,7 +15,7 @@ export class HelloController { @Get('async') async asyncGreeting(): Promise { - return await this.helloService.greeting(); + return this.helloService.greeting(); } @Get('stream') diff --git a/integration/hooks/src/enable-shutdown-hooks-main.ts b/integration/hooks/src/enable-shutdown-hooks-main.ts index 9ad29aadc27..ad771cd6e4d 100644 --- a/integration/hooks/src/enable-shutdown-hooks-main.ts +++ b/integration/hooks/src/enable-shutdown-hooks-main.ts @@ -1,8 +1,8 @@ import { - Injectable, - OnApplicationShutdown, BeforeApplicationShutdown, + Injectable, Module, + OnApplicationShutdown, } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; const SIGNAL = process.argv[2]; @@ -12,10 +12,12 @@ const SIGNAL_TO_LISTEN = process.argv[3]; class TestInjectable implements OnApplicationShutdown, BeforeApplicationShutdown { beforeApplicationShutdown(signal: string) { + // tslint:disable-next-line:no-console console.log('beforeApplicationShutdown ' + signal); } onApplicationShutdown(signal: string) { + // tslint:disable-next-line:no-console console.log('onApplicationShutdown ' + signal); } } diff --git a/integration/microservices/e2e/sum-mqtt.spec.ts b/integration/microservices/e2e/sum-mqtt.spec.ts index 21d0b011ed5..8ce00836f11 100644 --- a/integration/microservices/e2e/sum-mqtt.spec.ts +++ b/integration/microservices/e2e/sum-mqtt.spec.ts @@ -49,6 +49,7 @@ describe('MQTT transport', () => { .expect(200, '15'); }); + // tslint:disable-next-line:only-arrow-functions it(`/POST (concurrent)`, function() { return request(server) .post('/concurrent') diff --git a/integration/microservices/src/app.controller.ts b/integration/microservices/src/app.controller.ts index 32ad45f330d..ac9571f9a92 100644 --- a/integration/microservices/src/app.controller.ts +++ b/integration/microservices/src/app.controller.ts @@ -42,8 +42,8 @@ export class AppController { return result === expected; }; return data - .map(async tab => await send(tab)) - .reduce(async (a, b) => (await a) && (await b)); + .map(async tab => send(tab)) + .reduce(async (a, b) => (await a) && b); } @MessagePattern({ cmd: 'sum' }) diff --git a/integration/microservices/src/mqtt/mqtt.controller.ts b/integration/microservices/src/mqtt/mqtt.controller.ts index 22a12701af2..0f10c1a0c3a 100644 --- a/integration/microservices/src/mqtt/mqtt.controller.ts +++ b/integration/microservices/src/mqtt/mqtt.controller.ts @@ -45,9 +45,9 @@ export class MqttController { return result === expected; }; - return await data - .map(async tab => await send(tab)) - .reduce(async (a, b) => (await a) && (await b)); + return data + .map(async tab => send(tab)) + .reduce(async (a, b) => (await a) && b); } @Post('notify') diff --git a/integration/microservices/src/nats/nats.controller.ts b/integration/microservices/src/nats/nats.controller.ts index 5428d531898..8637ed42ba0 100644 --- a/integration/microservices/src/nats/nats.controller.ts +++ b/integration/microservices/src/nats/nats.controller.ts @@ -55,8 +55,8 @@ export class NatsController { return result === expected; }; return data - .map(async tab => await send(tab)) - .reduce(async (a, b) => (await a) && (await b)); + .map(async tab => send(tab)) + .reduce(async (a, b) => (await a) && b); } @MessagePattern('math.*') @@ -81,7 +81,7 @@ export class NatsController { @Get('exception') async getError() { - return await this.client + return this.client .send('exception', {}) .pipe(catchError(err => of(err))); } diff --git a/integration/microservices/src/redis/redis.controller.ts b/integration/microservices/src/redis/redis.controller.ts index ac179656659..49529f95d04 100644 --- a/integration/microservices/src/redis/redis.controller.ts +++ b/integration/microservices/src/redis/redis.controller.ts @@ -42,8 +42,8 @@ export class RedisController { return result === expected; }; return data - .map(async tab => await send(tab)) - .reduce(async (a, b) => (await a) && (await b)); + .map(async tab => send(tab)) + .reduce(async (a, b) => (await a) && b); } @MessagePattern({ cmd: 'sum' }) diff --git a/integration/microservices/src/rmq/rmq.controller.ts b/integration/microservices/src/rmq/rmq.controller.ts index f6ed8350390..b1195b7374c 100644 --- a/integration/microservices/src/rmq/rmq.controller.ts +++ b/integration/microservices/src/rmq/rmq.controller.ts @@ -53,8 +53,8 @@ export class RMQController { return result === expected; }; return data - .map(async tab => await send(tab)) - .reduce(async (a, b) => (await a) && (await b)); + .map(async tab => send(tab)) + .reduce(async (a, b) => (await a) && b); } @MessagePattern({ cmd: 'sum' }) diff --git a/integration/mongoose/src/cats/cats.service.ts b/integration/mongoose/src/cats/cats.service.ts index 6fced8043e7..51d6e313a88 100644 --- a/integration/mongoose/src/cats/cats.service.ts +++ b/integration/mongoose/src/cats/cats.service.ts @@ -10,10 +10,10 @@ export class CatsService { async create(createCatDto: CreateCatDto): Promise { const cat = new this.catModel(createCatDto); - return await cat.save(); + return cat.save(); } async findAll(): Promise { - return await this.catModel.find().exec(); + return this.catModel.find().exec(); } } diff --git a/integration/scopes/src/hello/guards/request-scoped.guard.ts b/integration/scopes/src/hello/guards/request-scoped.guard.ts index 76a40b480b6..6124eb7d5f4 100644 --- a/integration/scopes/src/hello/guards/request-scoped.guard.ts +++ b/integration/scopes/src/hello/guards/request-scoped.guard.ts @@ -12,7 +12,7 @@ export class Guard implements CanActivate { static COUNTER = 0; static REQUEST_SCOPED_DATA = []; - constructor(@Inject('REQUEST_ID') private requestId: number) { + constructor(@Inject('REQUEST_ID') private readonly requestId: number) { Guard.COUNTER++; } diff --git a/integration/scopes/src/hello/interceptors/logging.interceptor.ts b/integration/scopes/src/hello/interceptors/logging.interceptor.ts index e1b017d2649..30fa62d319e 100644 --- a/integration/scopes/src/hello/interceptors/logging.interceptor.ts +++ b/integration/scopes/src/hello/interceptors/logging.interceptor.ts @@ -13,7 +13,7 @@ export class Interceptor implements NestInterceptor { static COUNTER = 0; static REQUEST_SCOPED_DATA = []; - constructor(@Inject('REQUEST_ID') private requestId: number) { + constructor(@Inject('REQUEST_ID') private readonly requestId: number) { Interceptor.COUNTER++; } diff --git a/integration/scopes/src/hello/users/user-by-id.pipe.ts b/integration/scopes/src/hello/users/user-by-id.pipe.ts index ff5695c1147..385eedf2d8c 100644 --- a/integration/scopes/src/hello/users/user-by-id.pipe.ts +++ b/integration/scopes/src/hello/users/user-by-id.pipe.ts @@ -12,7 +12,7 @@ export class UserByIdPipe implements PipeTransform { static REQUEST_SCOPED_DATA = []; constructor( - @Inject('REQUEST_ID') private requestId: number, + @Inject('REQUEST_ID') private readonly requestId: number, private readonly usersService: UsersService, ) { UserByIdPipe.COUNTER++; diff --git a/integration/scopes/src/msvc/guards/request-scoped.guard.ts b/integration/scopes/src/msvc/guards/request-scoped.guard.ts index 76a40b480b6..6124eb7d5f4 100644 --- a/integration/scopes/src/msvc/guards/request-scoped.guard.ts +++ b/integration/scopes/src/msvc/guards/request-scoped.guard.ts @@ -12,7 +12,7 @@ export class Guard implements CanActivate { static COUNTER = 0; static REQUEST_SCOPED_DATA = []; - constructor(@Inject('REQUEST_ID') private requestId: number) { + constructor(@Inject('REQUEST_ID') private readonly requestId: number) { Guard.COUNTER++; } diff --git a/integration/scopes/src/msvc/interceptors/logging.interceptor.ts b/integration/scopes/src/msvc/interceptors/logging.interceptor.ts index e1b017d2649..30fa62d319e 100644 --- a/integration/scopes/src/msvc/interceptors/logging.interceptor.ts +++ b/integration/scopes/src/msvc/interceptors/logging.interceptor.ts @@ -13,7 +13,7 @@ export class Interceptor implements NestInterceptor { static COUNTER = 0; static REQUEST_SCOPED_DATA = []; - constructor(@Inject('REQUEST_ID') private requestId: number) { + constructor(@Inject('REQUEST_ID') private readonly requestId: number) { Interceptor.COUNTER++; } diff --git a/integration/typegraphql/src/common/interceptors/data.interceptor.ts b/integration/typegraphql/src/common/interceptors/data.interceptor.ts index d097280aeae..ea80b6508f9 100644 --- a/integration/typegraphql/src/common/interceptors/data.interceptor.ts +++ b/integration/typegraphql/src/common/interceptors/data.interceptor.ts @@ -10,6 +10,7 @@ import { tap } from 'rxjs/operators'; @Injectable() export class DataInterceptor implements NestInterceptor { intercept(context: ExecutionContext, next: CallHandler): Observable { + // tslint:disable-next-line:no-console return next.handle().pipe(tap(data => console.log(data))); } } diff --git a/integration/typeorm/src/photo/photo.service.ts b/integration/typeorm/src/photo/photo.service.ts index b708adff9ef..bbe7b892a44 100644 --- a/integration/typeorm/src/photo/photo.service.ts +++ b/integration/typeorm/src/photo/photo.service.ts @@ -11,7 +11,7 @@ export class PhotoService { ) {} async findAll(): Promise { - return await this.photoRepository.find(); + return this.photoRepository.find(); } async create(): Promise { @@ -20,6 +20,6 @@ export class PhotoService { photoEntity.description = 'Is great!'; photoEntity.views = 6000; - return await this.photoRepository.create(photoEntity); + return this.photoRepository.create(photoEntity); } } diff --git a/package.json b/package.json index 782ac094137..336dd891f24 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,10 @@ "coverage": "nyc report --reporter=text-lcov | coveralls", "test": "nyc --require ts-node/register mocha packages/**/*.spec.ts --reporter spec --retries 3 --require 'node_modules/reflect-metadata/Reflect.js'", "integration-test": "mocha \"integration/*/{,!(node_modules)/**/}/*.spec.ts\" --reporter spec --require ts-node/register --require 'node_modules/reflect-metadata/Reflect.js'", - "lint": "tslint -p tsconfig.json -c tslint.json \"packages/**/*.ts\" -e \"*.spec.ts\"", + "lint": "npm run lint:packages && npm run lint:integration && npm run lint:spec", + "lint:packages": "tslint -p tsconfig.json \"packages/**/*.ts\" --fix", + "lint:integration": "tslint -p tsconfig.json -c tslint.json \"integration/*/{,!(node_modules)/**/}/*.ts\" --fix", + "lint:spec": "tslint -p tsconfig.spec.json \"{packages,integration}/*/{,!(node_modules)/**/}/*.spec.ts\" --fix", "format": "prettier \"**/*.ts\" --ignore-path ./.prettierignore --write && git status", "clean": "gulp clean:bundle", "prebuild": "rm -rf node_modules/@nestjs", @@ -184,7 +187,8 @@ "lint-staged": { "packages/**/*.{ts,json}": [ "npm run format", - "git add" + "git add", + "tslint --fix" ] }, "husky": { diff --git a/packages/common/cache/interfaces/cache-manager.interface.ts b/packages/common/cache/interfaces/cache-manager.interface.ts index 86dbc2e0968..6a5b6c4239a 100644 --- a/packages/common/cache/interfaces/cache-manager.interface.ts +++ b/packages/common/cache/interfaces/cache-manager.interface.ts @@ -15,7 +15,11 @@ export interface CacheStore { * @param key cache key * @param value cache value */ - set(key: string, value: T, options?: CacheStoreSetOptions): Promise | void; + set( + key: string, + value: T, + options?: CacheStoreSetOptions, + ): Promise | void; /** * Retrieve a key/value pair from the cache. * diff --git a/packages/core/test/injector/injector.spec.ts b/packages/core/test/injector/injector.spec.ts index 9d9da523380..04458d57dff 100644 --- a/packages/core/test/injector/injector.spec.ts +++ b/packages/core/test/injector/injector.spec.ts @@ -29,7 +29,7 @@ describe('Injector', () => { class MainTest { @Inject() property: DependencyOne; - constructor(public depOne: DependencyOne, public depTwo: DependencyTwo) {} + constructor(public one: DependencyOne, public two: DependencyTwo) {} } let moduleDeps: Module; @@ -70,8 +70,8 @@ describe('Injector', () => { 'MainTest', ) as InstanceWrapper; - expect(instance.depOne).instanceof(DependencyOne); - expect(instance.depTwo).instanceof(DependencyTwo); + expect(instance.one).instanceof(DependencyOne); + expect(instance.two).instanceof(DependencyTwo); expect(instance).instanceof(MainTest); }); @@ -379,7 +379,7 @@ describe('Injector', () => { }); it('should return null when related modules do not have appropriate component', () => { - let module = { + let moduleFixture = { relatedModules: new Map([ [ 'key', @@ -395,10 +395,14 @@ describe('Injector', () => { ] as any), }; expect( - injector.lookupComponentInImports(module as any, metatype as any, null), + injector.lookupComponentInImports( + moduleFixture as any, + metatype as any, + null, + ), ).to.be.eventually.eq(null); - module = { + moduleFixture = { relatedModules: new Map([ [ 'key', @@ -414,12 +418,16 @@ describe('Injector', () => { ] as any), }; expect( - injector.lookupComponentInImports(module as any, metatype as any, null), + injector.lookupComponentInImports( + moduleFixture as any, + metatype as any, + null, + ), ).to.eventually.be.eq(null); }); it('should call "loadProvider" when component is not resolved', async () => { - const module = { + const moduleFixture = { imports: new Map([ [ 'key', @@ -440,7 +448,7 @@ describe('Injector', () => { ] as any), }; await injector.lookupComponentInImports( - module as any, + moduleFixture as any, metatype as any, new InstanceWrapper(), ); @@ -448,7 +456,7 @@ describe('Injector', () => { }); it('should not call "loadProvider" when component is resolved', async () => { - const module = { + const moduleFixture = { relatedModules: new Map([ [ 'key', @@ -468,7 +476,7 @@ describe('Injector', () => { ] as any), }; await injector.lookupComponentInImports( - module as any, + moduleFixture as any, metatype as any, null, ); diff --git a/packages/core/test/injector/module-token-factory.spec.ts b/packages/core/test/injector/module-token-factory.spec.ts index b4b02749849..30f96b8aab9 100644 --- a/packages/core/test/injector/module-token-factory.spec.ts +++ b/packages/core/test/injector/module-token-factory.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import safeStringify from 'fast-safe-stringify'; +import stringify from 'fast-safe-stringify'; import * as hash from 'object-hash'; import { SingleScope } from '../../../common'; import { ModuleTokenFactory } from '../../injector/module-token-factory'; @@ -41,7 +41,7 @@ describe('ModuleTokenFactory', () => { expect(token).to.be.deep.eq( hash({ module: Module.name, - dynamic: safeStringify({ + dynamic: stringify({ providers: [{}], }), scope: [Module.name], diff --git a/packages/core/test/router/router-proxy.spec.ts b/packages/core/test/router/router-proxy.spec.ts index 142b77c14bc..7822a7f1329 100644 --- a/packages/core/test/router/router-proxy.spec.ts +++ b/packages/core/test/router/router-proxy.spec.ts @@ -10,7 +10,7 @@ import { ExecutionContextHost } from '../../helpers/execution-context-host'; describe('RouterProxy', () => { let routerProxy: RouterProxy; let handler: ExceptionsHandler; - let httpException = new HttpException('test', 500); + const httpException = new HttpException('test', 500); let nextStub: sinon.SinonStub; beforeEach(() => { handler = new ExceptionsHandler(new NoopHttpAdapter({})); diff --git a/packages/microservices/test/serializers/kafka-request.serializer.spec.ts b/packages/microservices/test/serializers/kafka-request.serializer.spec.ts index 712122ab2bd..5cde5292e98 100644 --- a/packages/microservices/test/serializers/kafka-request.serializer.spec.ts +++ b/packages/microservices/test/serializers/kafka-request.serializer.spec.ts @@ -63,7 +63,7 @@ describe('KafkaRequestSerializer', () => { it('complex object with .toString()', () => { class Complex { - private name = 'complex'; + private readonly name = 'complex'; public toString(): string { return this.name; } @@ -77,7 +77,7 @@ describe('KafkaRequestSerializer', () => { it('complex object without .toString()', () => { class ComplexWithOutToString { - private name = 'complex'; + private readonly name = 'complex'; } expect(instance.serialize(new ComplexWithOutToString())).to.deep.eq({ diff --git a/tsconfig.spec.json b/tsconfig.spec.json index e38a1e0edb9..9b8cc85614c 100644 --- a/tsconfig.spec.json +++ b/tsconfig.spec.json @@ -1,6 +1,5 @@ { - "extends": "tsconfig.json", + "extends": "./tsconfig.json", "include": ["**/*.spec.ts"], - "include": ["src/**/*"], "exclude": ["node_modules", "dist"] }