mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
style(): run linter over packages, integration and spec files, add hook
This commit is contained in:
@@ -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<Cat> {
|
||||
return await this.catsService.findOneById(id);
|
||||
return this.catsService.findOneById(id);
|
||||
}
|
||||
|
||||
@Mutation('createCat')
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -15,7 +15,7 @@ export class HelloController {
|
||||
|
||||
@Get('async')
|
||||
async asyncGreeting(): Promise<string> {
|
||||
return await this.helloService.greeting();
|
||||
return this.helloService.greeting();
|
||||
}
|
||||
|
||||
@Get('stream')
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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' })
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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<number>('exception', {})
|
||||
.pipe(catchError(err => of(err)));
|
||||
}
|
||||
|
||||
@@ -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' })
|
||||
|
||||
@@ -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' })
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
|
||||
@@ -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++;
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export class PhotoService {
|
||||
) {}
|
||||
|
||||
async findAll(): Promise<Photo[]> {
|
||||
return await this.photoRepository.find();
|
||||
return this.photoRepository.find();
|
||||
}
|
||||
|
||||
async create(): Promise<Photo> {
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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<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);
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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({}));
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"extends": "tsconfig.json",
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["**/*.spec.ts"],
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user