Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SERVICES-1760] eslint fixes #1151

Open
wants to merge 13 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
project: true,
tsconfigRootDir: __dirname,
},
plugins: ['@typescript-eslint/eslint-plugin'],
plugins: ['@typescript-eslint'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
Expand All @@ -16,8 +16,15 @@ module.exports = {
jest: true,
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
"@typescript-eslint/no-explicit-any": ["off"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
],
}
};
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: ESLint

on:
pull_request:
branches: [main, development, feat/**]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run lint
409 changes: 224 additions & 185 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
"@types/node": "^17.0.41",
"@types/passport-jwt": "^3.0.6",
"@types/passport-local": "^1.0.34",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
Expand Down
4 changes: 2 additions & 2 deletions src/common.app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as Transport from 'winston-transport';
import { ApiConfigService } from './helpers/api.config.service';
import { RedisPubSubModule } from './services/redis.pubSub.module';

const loglevel = !!process.env.LOG_LEVEL ? process.env.LOG_LEVEL : 'error';
const loglevel = process.env.LOG_LEVEL ? process.env.LOG_LEVEL : 'error';

const logTransports: Transport[] = [
new winston.transports.Console({
Expand All @@ -24,7 +24,7 @@ const logTransports: Transport[] = [
}),
];

if (!!process.env.LOG_FILE) {
if (process.env.LOG_FILE) {
logTransports.push(
new winston.transports.File({
filename: process.env.LOG_FILE,
Expand Down
2 changes: 0 additions & 2 deletions src/helpers/elastic.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ export function buildElasticQuery(query: ElasticQuery) {
};

if (Object.keys(elasticQuery.query.bool).length === 0) {
//@ts-ignore
delete elasticQuery.query.bool;

//@ts-ignore
elasticQuery.query['match_all'] = {};
}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/elastic.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ElasticService {
let response = await this.elasticClient.search(params);
const hits = [];
let scroll = 1;
while (true) {
for (;;) {
const sourceHits = response.body.hits.hits;

if (sourceHits.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/validators/metric.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class IsValidMetricConstraint implements ValidatorConstraintInterface {
}

export function IsValidMetric(validationOptions?: ValidationOptions) {
return (object: Object, propertyName: string) => {
return (object: object, propertyName: string) => {
registerDecorator({
target: object.constructor,
propertyName: propertyName,
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/validators/series.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class IsValidSeriesConstraint implements ValidatorConstraintInterface {
}

export function IsValidSeries(validationOptions?: ValidationOptions) {
return (object: Object, propertyName: string) => {
return (object: object, propertyName: string) => {
registerDecorator({
target: object.constructor,
propertyName: propertyName,
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/validators/unix.time.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class IsValidUnixTimeConstraint implements ValidatorConstraintInterface {
}

export function IsValidUnixTime(validationOptions?: ValidationOptions) {
return (object: Object, propertyName: string) => {
return (object: object, propertyName: string) => {
registerDecorator({
target: object.constructor,
propertyName: propertyName,
Expand Down
4 changes: 0 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ async function bootstrap() {
const apiConfigService = app.get<ApiConfigService>(ApiConfigService);
const httpServer = httpAdapterHostService.httpAdapter.getHttpServer();

if (apiConfigService.isTracerActive()) {
require('dd-trace').init();
}

httpServer.keepAliveTimeout =
apiConfigService.getKeepAliveTimeoutUpstream();
httpServer.headersTimeout = apiConfigService.getKeepAliveTimeoutUpstream(); //`keepAliveTimeout + server's expected response time`
Expand Down
8 changes: 2 additions & 6 deletions src/modules/analytics/analytics.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ export class AnalyticsResolver {
skipUndefinedProperties: true,
}),
)
async latestHistoricData(
@Args() args: AnalyticsQueryArgs,
): Promise<HistoricDataModel[]> {
async latestHistoricData(): Promise<HistoricDataModel[]> {
return [];
}

Expand All @@ -163,9 +161,7 @@ export class AnalyticsResolver {
skipUndefinedProperties: true,
}),
)
async latestBinnedHistoricData(
@Args() args: AnalyticsQueryArgs,
): Promise<HistoricDataModel[]> {
async latestBinnedHistoricData(): Promise<HistoricDataModel[]> {
return [];
}
}
6 changes: 3 additions & 3 deletions src/modules/analytics/mocks/analytics.compute.service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ export class AnalyticsComputeServiceMock implements IAnalyticsComputeService {
totalValueStakedUSD(): Promise<string> {
throw new Error('Method not implemented.');
}
totalAggregatedRewards(days: number): Promise<string> {
totalAggregatedRewards(): Promise<string> {
throw new Error('Method not implemented.');
}
totalLockedMexStakedUSD(): Promise<string> {
throw new Error('Method not implemented.');
}
feeTokenBurned(tokenID: string, time: string): Promise<string> {
feeTokenBurned(): Promise<string> {
throw new Error('Method not implemented.');
}
penaltyTokenBurned(tokenID: string, time: string): Promise<string> {
penaltyTokenBurned(): Promise<string> {
throw new Error('Method not implemented.');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class AutoRouterComputeService {
pairs: PairModel[],
initialAmountIn: string,
): Array<string[]> {
const intermediaryAmounts: Array<string[]> = new Array();
const intermediaryAmounts: Array<string[]> = [];

for (const path of paths) {
const pathAmounts: string[] = [];
Expand Down Expand Up @@ -132,7 +132,7 @@ export class AutoRouterComputeService {
pairs: PairModel[],
fixedAmountOut: string,
): Array<string[]> {
const intermediaryAmounts: Array<string[]> = new Array();
const intermediaryAmounts: Array<string[]> = [];

for (const path of paths) {
const pathAmounts: string[] = [];
Expand Down
20 changes: 16 additions & 4 deletions src/modules/auto-router/services/auto-router.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export class AutoRouterService {
),
oneMinute() * 10,
);
} catch (error) {}
} catch (error) {
this.logger.error('Error when getting all paths', error);
}
}

async swap(args: AutoRouterArgs): Promise<AutoRouteModel> {
Expand Down Expand Up @@ -146,9 +148,19 @@ export class AutoRouterService {
this.pairCompute.tokenPriceUSD(tokenOutID),
]);

let [amountIn, amountOut] = this.isFixedInput(swapType)
? [args.amountIn, result]
: [result, args.amountOut];
// let [amountIn, amountOut] = this.isFixedInput(swapType)
// ? [args.amountIn, result]
dragos-rebegea marked this conversation as resolved.
Show resolved Hide resolved
// : [result, args.amountOut];

let amountIn: string;
let amountOut: string;
if (this.isFixedInput(swapType)) {
amountIn = args.amountIn;
amountOut = result;
} else {
amountIn = result;
amountOut = args.amountOut;
}

const [tokenInExchangeRate, tokenOutExchangeRate] =
this.calculateExchangeRate(
Expand Down
11 changes: 3 additions & 8 deletions src/modules/energy/mocks/energy.abi.service.mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EnergyType } from '@multiversx/sdk-exchange';
import BigNumber from 'bignumber.js';
import { LockOption } from '../models/simple.lock.energy.model';
import { IEnergyAbiService } from '../services/interfaces';
import { EnergyAbiService } from '../services/energy.abi.service';
Expand All @@ -23,17 +22,13 @@ export class EnergyAbiServiceMock implements IEnergyAbiService {
async ownerAddress(): Promise<string> {
throw new Error('Method not implemented.');
}
async energyEntryForUser(userAddress: string): Promise<EnergyType> {
async energyEntryForUser(): Promise<EnergyType> {
throw new Error('Method not implemented.');
}
async energyAmountForUser(userAddress: string): Promise<string> {
async energyAmountForUser(): Promise<string> {
throw new Error('Method not implemented.');
}
async getPenaltyAmount(
tokenAmount: BigNumber,
prevLockEpochs: number,
epochsToReduce: number,
): Promise<string> {
async getPenaltyAmount(): Promise<string> {
throw new Error('Method not implemented.');
}
async isPaused(): Promise<boolean> {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/energy/validators/locked.tokens.validator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArgumentMetadata, Injectable, PipeTransform } from '@nestjs/common';
import { Injectable, PipeTransform } from '@nestjs/common';
import { UserInputError } from 'apollo-server-express';
import { InputTokenModel } from 'src/models/inputToken.model';
import { EnergyAbiService } from '../services/energy.abi.service';
Expand All @@ -7,7 +7,7 @@ import { EnergyAbiService } from '../services/energy.abi.service';
export class LockedEnergyTokensValidationPipe implements PipeTransform {
constructor(private readonly energyAbi: EnergyAbiService) {}

async transform(value: InputTokenModel[], metadata: ArgumentMetadata) {
async transform(value: InputTokenModel[]) {
const lockedTokenID = await this.energyAbi.lockedTokenID();
const lockedTokens = [];

Expand Down
9 changes: 7 additions & 2 deletions src/modules/escrow/escrow.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import { EscrowTransactionService } from './services/escrow.transaction.service';
import { SenderCooldownValidator } from './validators/sender.cooldown.validator';
import { TransferTokensValidator } from './validators/transfer.tokens.validator';
import { EscrowAdminValidator } from './validators/admin.validator';
import { ForbiddenError } from 'apollo-server-express';
import { EscrowAbiService } from './services/escrow.abi.service';

Expand Down Expand Up @@ -141,8 +140,14 @@ export class EscrowResolver {
async cancelEscrowTransfer(
@Args('sender') sender: string,
@Args('receiver') receiver: string,
@AuthUser(EscrowAdminValidator) _user: UserAuthResult,
@AuthUser() user: UserAuthResult,
): Promise<TransactionModel> {
const permissions = await this.escrowAbi.addressPermission(
user.address,
);
if (!permissions.includes(SCPermissions.ADMIN)) {
throw new ForbiddenError('User is not an admin');
}
return this.escrowTransaction.cancelTransfer(sender, receiver);
}

Expand Down
20 changes: 0 additions & 20 deletions src/modules/escrow/validators/admin.validator.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/modules/escrow/validators/sender.cooldown.validator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArgumentMetadata, Injectable, PipeTransform } from '@nestjs/common';
import { Injectable, PipeTransform } from '@nestjs/common';
import { ForbiddenError } from 'apollo-server-express';
import { UserAuthResult } from 'src/modules/auth/user.auth.result';
import { EscrowComputeService } from '../services/escrow.compute.service';
Expand All @@ -7,7 +7,7 @@ import { EscrowComputeService } from '../services/escrow.compute.service';
export class SenderCooldownValidator implements PipeTransform {
constructor(private readonly escrowCompute: EscrowComputeService) {}

async transform(value: UserAuthResult, metadata: ArgumentMetadata) {
async transform(value: UserAuthResult) {
const isAddressOnCooldown =
await this.escrowCompute.isSenderAddressOnCooldown(value.address);
if (isAddressOnCooldown) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/escrow/validators/transfer.tokens.validator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArgumentMetadata, Injectable, PipeTransform } from '@nestjs/common';
import { Injectable, PipeTransform } from '@nestjs/common';
import { UserInputError } from 'apollo-server-express';
import { InputTokenModel } from 'src/models/inputToken.model';
import { EscrowAbiService } from '../services/escrow.abi.service';
Expand All @@ -7,7 +7,7 @@ import { EscrowAbiService } from '../services/escrow.abi.service';
export class TransferTokensValidator implements PipeTransform {
constructor(private readonly escrowAbi: EscrowAbiService) {}

async transform(value: InputTokenModel[], metadata: ArgumentMetadata) {
async transform(value: InputTokenModel[]) {
const lockedTokenID = await this.escrowAbi.lockedTokenID();
for (const payment of value) {
if (payment.tokenID !== lockedTokenID || payment.nonce < 1) {
Expand Down
1 change: 0 additions & 1 deletion src/modules/farm/base-module/farm.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Resolver, ResolveField, Parent } from '@nestjs/graphql';
import { BaseFarmModel } from '../models/farm.model';
import { PairModel } from '../../pair/models/pair.model';
import { LockedAssetModel } from '../../locked-asset-factory/models/locked-asset.model';
import { EsdtToken } from '../../tokens/models/esdtToken.model';
import { NftCollection } from '../../tokens/models/nftCollection.model';
import { Address } from '@multiversx/sdk-core';
Expand Down
12 changes: 11 additions & 1 deletion src/modules/farm/base-module/services/farm.abi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { CacheTtlInfo } from 'src/services/caching/cache.ttl.info';
import { oneHour } from 'src/helpers/helpers';
import { MXApiService } from 'src/services/multiversx-communication/mx.api.service';
import { IFarmAbiService } from './interfaces';
import { farmVersion } from 'src/utils/farm.utils';
import { FarmVersion } from '../../models/farm.model';

export class FarmAbiService
extends GenericAbiService
Expand Down Expand Up @@ -330,7 +332,15 @@ export class FarmAbiService
}

async getBurnGasLimitRaw(farmAddress: string): Promise<string | undefined> {
return undefined;
if (farmVersion(farmAddress) === FarmVersion.V1_2) {
return undefined;
}

const contract = await this.mxProxy.getFarmSmartContract(farmAddress);
const interaction: Interaction =
contract.methodsExplicit.getBurnGasLimit();
const response = await this.getGenericData(interaction);
return response.firstValue.valueOf().toFixed();
}

@ErrorLoggerAsync({
Expand Down
Loading