Skip to content

Commit

Permalink
fix(): all linter rules
Browse files Browse the repository at this point in the history
  • Loading branch information
NarHakobyan committed Jun 22, 2020
1 parent 9a1f343 commit 70b9040
Show file tree
Hide file tree
Showing 28 changed files with 174 additions and 230 deletions.
12 changes: 6 additions & 6 deletions .development.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ TRANSPORT_PORT=4000
JWT_SECRET_KEY=rxPhglGJWPlOW596
JWT_EXPIRATION_TIME=3600

# Postgres envioroment variables
POSTGRES_HOST=127.0.0.1
POSTGRES_PORT=5432
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DATABASE=nest_boilerplate
# Database envioroment variables
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_DATABASE=nest_boilerplate

# aws configurations
## AWS S3
Expand Down
48 changes: 13 additions & 35 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
},
'parser': '@typescript-eslint/parser',
'parserOptions': {
'project': path.resolve(__dirname, './tsconfig.json'),
'project': path.resolve(__dirname, './tsconfig.eslint.json'),
'sourceType': 'module',
},
extends: [
Expand Down Expand Up @@ -90,9 +90,18 @@ module.exports = {
'error',
'always',
],
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/naming-convention': [
'error',
{ selector: 'default', format: ['camelCase', 'PascalCase', 'snake_case', 'UPPER_CASE'] },
{
selector: 'default', format: ['camelCase', 'PascalCase', 'snake_case', 'UPPER_CASE'], 'filter': {
'regex': '^_.*$',
'match': false,
},
},
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE'],
Expand Down Expand Up @@ -148,15 +157,13 @@ module.exports = {
},
},
}],
// ORIGINAL tslint.json -> 'interface-name': false,
'@typescript-eslint/interface-name-prefix': 'off',

// ORIGINAL tslint.json -> 'no-console': [true, 'debug', 'info', 'time', 'timeEnd', 'trace'],
'no-restricted-syntax': [
'error',
{
selector:
'CallExpression[callee.object.name=\'console\'][callee.property.name=/^(debug|info|time|timeEnd|trace)$/]',
'CallExpression[callee.object.name=\'console\'][callee.property.name=/^(debug|log|time|timeEnd|trace)$/]',
message: 'Unexpected property on console object was called',
},
],
Expand Down Expand Up @@ -199,35 +206,6 @@ module.exports = {
'no-bitwise': 'error',
'no-caller': 'error',
'no-cond-assign': 'error',
'no-console': [
'error',
{
'allow': [
'info',
'dirxml',
'warn',
'error',
'dir',
'timeLog',
'assert',
'clear',
'count',
'countReset',
'group',
'groupCollapsed',
'groupEnd',
'table',
'Console',
'markTimeline',
'profile',
'profileEnd',
'timeline',
'timelineEnd',
'timeStamp',
'context',
],
},
],
'no-debugger': 'error',
'no-duplicate-case': 'error',
'no-duplicate-imports': 'error',
Expand Down Expand Up @@ -368,7 +346,7 @@ module.exports = {
],
'no-accessor-recursion': true,
'no-collapsible-if': true,
'no-implicit-dependencies': true,
'no-implicit-dependencies': [true, 'dev'],
'no-multi-spaces': true,
'no-reference-import': true,
'no-return-undefined': [
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: postgres
DB_PASSWORD: postgres
ports:
- "5433:5432"
volumes:
Expand Down
10 changes: 5 additions & 5 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ yarn install
Before start install PostgreSQL and fill correct configurations in `.development.env` file

```env
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DATABASE=nest_boilerplate
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_DATABASE=nest_boilerplate
```

Some helper script to work with database
Expand Down
22 changes: 10 additions & 12 deletions ormconfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import './src/boilerplate.polyfill';

import * as dotenv from 'dotenv';

import { SnakeNamingStrategy } from './src/snake-naming.strategy';
import './src/boilerplate.polyfill';

if (!(<any>module).hot /* for webpack HMR */) {
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
Expand All @@ -17,16 +19,12 @@ for (const envName of Object.keys(process.env)) {

module.exports = {
type: 'postgres',
host: process.env.POSTGRES_HOST,
port: +process.env.POSTGRES_PORT,
username: process.env.POSTGRES_USERNAME,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DATABASE,
host: process.env.DB_HOST,
port: +process.env.DB_PORT,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
namingStrategy: new SnakeNamingStrategy(),
entities: [
'src/modules/**/*.entity{.ts,.js}',
],
migrations: [
'src/migrations/*{.ts,.js}',
],
entities: ['src/modules/**/*.entity{.ts,.js}'],
migrations: ['src/migrations/*{.ts,.js}'],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"uuid": "^8.1.0"
},
"devDependencies": {
"@nestjs/testing": "^7.0.8",
"@nestjs/testing": "^7.2.0",
"@types/bcrypt": "^3.0.0",
"@types/compression": "^1.7.0",
"@types/dotenv": "^6.1.1",
Expand Down
6 changes: 3 additions & 3 deletions src/boilerplate.polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { AbstractEntity } from './common/abstract.entity';
import { AbstractDto } from './common/dto/AbstractDto';

declare global {
// tslint:disable-next-line:naming-convention no-unused
// eslint-disable-next-line @typescript-eslint/naming-convention,@typescript-eslint/tslint/config
interface Array<T> {
toDtos<B extends AbstractDto>(this: AbstractEntity<B>[]): B[];
}
}

Array.prototype.toDtos = function<B extends AbstractDto>(options?: any): B[] {
Array.prototype.toDtos = function <B extends AbstractDto>(options?: any): B[] {
// tslint:disable-next-line:no-invalid-this
return <B[]>_(this)
.map(item => item.toDto(options))
.map((item) => item.toDto(options))
.compact()
.value();
};
1 change: 1 addition & 0 deletions src/decorators/auth-user.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';

// eslint-disable-next-line @typescript-eslint/naming-convention
export const AuthUser = createParamDecorator(
(data: unknown, ctx: ExecutionContext) => {
const request = ctx.switchToHttp().getRequest();
Expand Down
1 change: 1 addition & 0 deletions src/decorators/roles.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import { SetMetadata } from '@nestjs/common';

import { RoleType } from '../common/constants/role-type';

// eslint-disable-next-line @typescript-eslint/naming-convention
export const Roles = (...roles: RoleType[]) => SetMetadata('roles', roles);
7 changes: 4 additions & 3 deletions src/decorators/swagger.schema.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { ApiBody } from '@nestjs/swagger';
import { SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';

// eslint-disable-next-line @typescript-eslint/naming-convention
export const ApiFile = (
fileName = 'file',
options: Partial<{ required: boolean; isArray: boolean }> = {},
options: Partial<{ isRequired: boolean; isArray: boolean }> = {},
): MethodDecorator => (
target: any,
propertyKey: string,
descriptor: PropertyDescriptor,
) => {
const { required = false, isArray = false } = options;
const { isRequired = false, isArray = false } = options;
let fileSchema: SchemaObject = {
type: 'string',
format: 'binary',
Expand All @@ -22,7 +23,7 @@ export const ApiFile = (
};
}
ApiBody({
required,
required: isRequired,
type: 'multipart/form-data',
schema: {
type: 'object',
Expand Down
6 changes: 3 additions & 3 deletions src/decorators/transforms.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import * as _ from 'lodash';
export function Trim() {
return Transform((value: string | string[]) => {
if (_.isArray(value)) {
return value.map(v => _.trim(v).replace(/\s\s+/g, ' '));
return value.map((v) => _.trim(v).replace(/\s\s+/g, ' '));
}
return _.trim(value).replace(/\s\s+/g, ' ');
});
Expand All @@ -32,7 +32,7 @@ export function Trim() {
* @constructor
*/
export function ToInt() {
return Transform(value => parseInt(value, 10), { toClassOnly: true });
return Transform((value) => parseInt(value, 10), { toClassOnly: true });
}

/**
Expand All @@ -45,7 +45,7 @@ export function ToInt() {
*/
export function ToArray(): (target: any, key: string) => void {
return Transform(
value => {
(value) => {
if (_.isNil(value)) {
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/file-not-image.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { BadRequestException } from '@nestjs/common';

export class FileNotImageException extends BadRequestException {
constructor(message?: string | object | any, error?: string) {
constructor(message?: string | any, error?: string) {
if (message) {
super(message, error);
} else {
Expand Down
8 changes: 2 additions & 6 deletions src/filters/constraint-errors.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/* eslint-disable camelcase */
/* eslint-disable @typescript-eslint/naming-convention */

interface IConstraintErrors {
[constraintKey: string]: string;
}

export const ConstraintErrors: IConstraintErrors = {
export const constraintErrors: Record<string, string> = {
UQ_97672ac88f789774dd47f7c8be3: 'error.unique.email',
};
4 changes: 2 additions & 2 deletions src/filters/query-failed.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Response } from 'express';
import { STATUS_CODES } from 'http';
import { QueryFailedError } from 'typeorm';

import { ConstraintErrors } from './constraint-errors';
import { constraintErrors } from './constraint-errors';

@Catch(QueryFailedError)
export class QueryFailedFilter implements ExceptionFilter {
Expand All @@ -19,7 +19,7 @@ export class QueryFailedFilter implements ExceptionFilter {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();

const errorMessage = ConstraintErrors[exception.constraint];
const errorMessage = constraintErrors[exception.constraint];

const status =
exception.constraint && exception.constraint.startsWith('UQ')
Expand Down
2 changes: 2 additions & 0 deletions src/guards/auth.guard.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AuthGuard as NestAuthGuard } from '@nestjs/passport';

// This should be used as guard class
// eslint-disable-next-line @typescript-eslint/naming-convention
export const AuthGuard = NestAuthGuard('jwt');
4 changes: 2 additions & 2 deletions src/main.hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { setupSwagger } from './viveo-swagger';

declare const module: any;

async function bootstrap() {
async function bootstrap(): Promise<void> {
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
cors: true,
bodyParser: true,
Expand Down Expand Up @@ -76,4 +76,4 @@ async function bootstrap() {
}
}

bootstrap();
void bootstrap();
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ async function bootstrap() {
console.info(`server running on port ${port}`);
}

bootstrap();
void bootstrap();
2 changes: 1 addition & 1 deletion src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class UserController {
@Get('admin')
@Roles(RoleType.USER)
@HttpCode(HttpStatus.OK)
async admin(@AuthUser() user: UserEntity) {
admin(@AuthUser() user: UserEntity): string {
return 'only for you admin: ' + user.firstName;
}

Expand Down
4 changes: 2 additions & 2 deletions src/providers/utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class UtilsService {
options?: any,
): T | T[] {
if (_.isArray(entity)) {
return entity.map(u => new model(u, options));
return entity.map((u) => new model(u, options));
}

return new model(entity, options);
Expand All @@ -44,7 +44,7 @@ export class UtilsService {
* generate random string
* @param length
*/
static generateRandomString(length: number) {
static generateRandomString(length: number): string {
return Math.random()
.toString(36)
.replace(/[^a-zA-Z0-9]+/g, '')
Expand Down
2 changes: 1 addition & 1 deletion src/shared/services/aws-s3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class AwsS3Service {
this._s3 = new AWS.S3(options);
}

async uploadImage(file: IFile) {
async uploadImage(file: IFile): Promise<string> {
const fileName = this.generatorService.fileName(
<string>mime.extension(file.mimetype),
);
Expand Down
13 changes: 5 additions & 8 deletions src/shared/services/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
import * as dotenv from 'dotenv';

Expand All @@ -17,8 +16,6 @@ export class ConfigService {
for (const envName of Object.keys(process.env)) {
process.env[envName] = process.env[envName].replace(/\\n/g, '\n');
}

console.info(process.env);
}

public get(key: string): string {
Expand Down Expand Up @@ -64,11 +61,11 @@ export class ConfigService {
migrations,
keepConnectionAlive: true,
type: 'postgres',
host: this.get('POSTGRES_HOST'),
port: this.getNumber('POSTGRES_PORT'),
username: this.get('POSTGRES_USERNAME'),
password: this.get('POSTGRES_PASSWORD'),
database: this.get('POSTGRES_DATABASE'),
host: this.get('DB_HOST'),
port: this.getNumber('DB_PORT'),
username: this.get('DB_USERNAME'),
password: this.get('DB_PASSWORD'),
database: this.get('DB_DATABASE'),
subscribers: [UserSubscriber],
migrationsRun: true,
logging: this.nodeEnv === 'development',
Expand Down
Loading

0 comments on commit 70b9040

Please sign in to comment.