Skip to content

Commit

Permalink
style(): run linter over packages, integration and spec files, add hook
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Nov 29, 2019
1 parent a08d1aa commit c3f4ea3
Show file tree
Hide file tree
Showing 25 changed files with 68 additions and 49 deletions.
4 changes: 2 additions & 2 deletions integration/graphql/src/cats/cats.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export class CatsResolvers {
@Query()
@UseGuards(CatsGuard)
async getCats() {
return await this.catsService.findAll();
return this.catsService.findAll();
}

@Query('cat')
async findOneById(
@Args('id', ParseIntPipe)
id: number,
): Promise<Cat> {
return await this.catsService.findOneById(id);
return this.catsService.findOneById(id);
}

@Mutation('createCat')
Expand Down
4 changes: 2 additions & 2 deletions integration/hello-world/e2e/interceptors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion integration/hello-world/src/hello/hello.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class HelloController {

@Get('async')
async asyncGreeting(): Promise<string> {
return await this.helloService.greeting();
return this.helloService.greeting();
}

@Get('stream')
Expand Down
6 changes: 4 additions & 2 deletions integration/hooks/src/enable-shutdown-hooks-main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
Injectable,
OnApplicationShutdown,
BeforeApplicationShutdown,
Injectable,
Module,
OnApplicationShutdown,
} from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
const SIGNAL = process.argv[2];
Expand All @@ -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);
}
}
Expand Down
1 change: 1 addition & 0 deletions integration/microservices/e2e/sum-mqtt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions integration/microservices/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down
6 changes: 3 additions & 3 deletions integration/microservices/src/mqtt/mqtt.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions integration/microservices/src/nats/nats.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.*')
Expand All @@ -81,7 +81,7 @@ export class NatsController {

@Get('exception')
async getError() {
return await this.client
return this.client
.send<number>('exception', {})
.pipe(catchError(err => of(err)));
}
Expand Down
4 changes: 2 additions & 2 deletions integration/microservices/src/redis/redis.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down
4 changes: 2 additions & 2 deletions integration/microservices/src/rmq/rmq.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down
4 changes: 2 additions & 2 deletions integration/mongoose/src/cats/cats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export class CatsService {

async create(createCatDto: CreateCatDto): Promise<Cat> {
const cat = new this.catModel(createCatDto);
return await cat.save();
return cat.save();
}

async findAll(): Promise<Cat[]> {
return await this.catModel.find().exec();
return this.catModel.find().exec();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand Down
2 changes: 1 addition & 1 deletion integration/scopes/src/hello/users/user-by-id.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class UserByIdPipe implements PipeTransform<string> {
static REQUEST_SCOPED_DATA = [];

constructor(
@Inject('REQUEST_ID') private requestId: number,
@Inject('REQUEST_ID') private readonly requestId: number,
private readonly usersService: UsersService,
) {
UserByIdPipe.COUNTER++;
Expand Down
2 changes: 1 addition & 1 deletion integration/scopes/src/msvc/guards/request-scoped.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { tap } from 'rxjs/operators';
@Injectable()
export class DataInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
// tslint:disable-next-line:no-console
return next.handle().pipe(tap(data => console.log(data)));
}
}
4 changes: 2 additions & 2 deletions integration/typeorm/src/photo/photo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class PhotoService {
) {}

async findAll(): Promise<Photo[]> {
return await this.photoRepository.find();
return this.photoRepository.find();
}

async create(): Promise<Photo> {
Expand All @@ -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);
}
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -184,7 +187,8 @@
"lint-staged": {
"packages/**/*.{ts,json}": [
"npm run format",
"git add"
"git add",
"tslint --fix"
]
},
"husky": {
Expand Down
6 changes: 5 additions & 1 deletion packages/common/cache/interfaces/cache-manager.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export interface CacheStore {
* @param key cache key
* @param value cache value
*/
set<T>(key: string, value: T, options?: CacheStoreSetOptions<T>): Promise<void> | void;
set<T>(
key: string,
value: T,
options?: CacheStoreSetOptions<T>,
): Promise<void> | void;
/**
* Retrieve a key/value pair from the cache.
*
Expand Down
30 changes: 19 additions & 11 deletions packages/core/test/injector/injector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,8 +70,8 @@ describe('Injector', () => {
'MainTest',
) as InstanceWrapper<MainTest>;

expect(instance.depOne).instanceof(DependencyOne);
expect(instance.depTwo).instanceof(DependencyTwo);
expect(instance.one).instanceof(DependencyOne);
expect(instance.two).instanceof(DependencyTwo);
expect(instance).instanceof(MainTest);
});

Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -440,15 +448,15 @@ describe('Injector', () => {
] as any),
};
await injector.lookupComponentInImports(
module as any,
moduleFixture as any,
metatype as any,
new InstanceWrapper(),
);
expect(loadProvider.called).to.be.true;
});

it('should not call "loadProvider" when component is resolved', async () => {
const module = {
const moduleFixture = {
relatedModules: new Map([
[
'key',
Expand All @@ -468,7 +476,7 @@ describe('Injector', () => {
] as any),
};
await injector.lookupComponentInImports(
module as any,
moduleFixture as any,
metatype as any,
null,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/injector/module-token-factory.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('ModuleTokenFactory', () => {
expect(token).to.be.deep.eq(
hash({
module: Module.name,
dynamic: safeStringify({
dynamic: stringify({
providers: [{}],
}),
scope: [Module.name],
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/router/router-proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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({
Expand Down
Loading

0 comments on commit c3f4ea3

Please sign in to comment.