Skip to content

Commit

Permalink
feat: apply no-implicit-coercion lint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Pigrabbit committed Jul 24, 2023
1 parent c48f5d8 commit b5a51f4
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
project: ['./tsconfig.json'],
},
rules: {
'no-implicit-coercion': 'error',
'max-classes-per-file': ['error', { ignoreExpressions: true }],
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-unused-vars': [
Expand Down
4 changes: 2 additions & 2 deletions spec/pgsql/pgsql.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ describe('Search complex conditions', () => {
expect(updateBody.id).toEqual(createBody.id);
expect(updateBody.name).toBe('changed');

const newId = +createBody.id + 1;
const newId = Number(createBody.id) + 1;
const { body: upsertBody } = await request(app.getHttpServer()).put(`/base/${newId}`).send({ name: 'name2' }).expect(HttpStatus.OK);
expect(+upsertBody.id).toEqual(newId);
expect(Number(upsertBody.id)).toEqual(newId);
expect(upsertBody.name).toEqual('name2');

const { body: deleteBody } = await request(app.getHttpServer()).delete(`/base/${createBody.id}`).expect(HttpStatus.OK);
Expand Down
2 changes: 1 addition & 1 deletion spec/relation-entities/comment-relation.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class CommentRelationInterceptor extends CustomRequestInterceptor {
async overrideOptions(req: Request): Promise<CustomReadOneRequestOptions> {
return new Promise((resolve, _reject) => {
resolve({
relations: +req.params.id % 2 === 0 ? ['writer'] : [],
relations: Number(req.params.id) % 2 === 0 ? ['writer'] : [],
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion spec/request-interceptor/delete.request.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CustomRequestInterceptor, CustomDeleteRequestOptions } from '../../src'
@Injectable()
export class DeleteRequestInterceptor extends CustomRequestInterceptor {
async overrideOptions(req: Request): Promise<CustomDeleteRequestOptions> {
const softDeleted = +req.params.id > 2 ? undefined : false;
const softDeleted = Number(req.params.id) > 2 ? undefined : false;

return new Promise((resolve, _reject) => {
resolve({
Expand Down
2 changes: 1 addition & 1 deletion spec/request-interceptor/read-one.request.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class ReadOneRequestInterceptor extends CustomRequestInterceptor {
return new Promise((resolve, _reject) => {
resolve({
fields: req.params.id === '1' ? ['name', 'createdAt'] : undefined,
softDeleted: +req.params.id % 2 === 0,
softDeleted: Number(req.params.id) % 2 === 0,
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion spec/response-interceptor/response-custom.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ResponseCustomInterceptor implements NestInterceptor {
? data
: {
..._.omit(data, ['deletedAt', 'lastModifiedAt']),
createdAt: +data.createdAt,
createdAt: Number(data.createdAt),
custom: Date.now(),
};
}),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/crud.route.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class CrudRouteFactory {
const entityColumns = columnList.map(({ propertyName, options }) => ({
name: propertyName,
type: options.type,
isPrimary: !!options.primary,
isPrimary: Boolean(options.primary),
}));

this.entity.columns = entityColumns;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/interceptor/search-request.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ export function SearchRequestInterceptor(crudOptions: CrudOptions, factoryOption
if (take == null) {
throw new UnprocessableEntityException('take must be positive number type');
}
const takeNumber = +take;
const takeNumber = Number(take);
if (!Number.isInteger(takeNumber) || takeNumber < 1) {
throw new UnprocessableEntityException('take must be positive number type');
}
if (!!limitOfTake && takeNumber > limitOfTake) {
if (limitOfTake !== undefined && takeNumber > limitOfTake) {
throw new UnprocessableEntityException(`take must be less than ${limitOfTake}`);
}
return takeNumber;
Expand Down

0 comments on commit b5a51f4

Please sign in to comment.