Skip to content

Commit

Permalink
Eslint update (#412)
Browse files Browse the repository at this point in the history
* Upgrade lint dependencies, fix lint
  • Loading branch information
forshtat authored Jun 23, 2020
1 parent dcd7abb commit 704b4a5
Show file tree
Hide file tree
Showing 37 changed files with 334 additions and 346 deletions.
30 changes: 16 additions & 14 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module.exports = {
env: {
'browser': true,
'es6': true,
'jest': true,
'mocha': true,
'node': true,
browser: true,
es6: true,
jest: true,
mocha: true,
node: true
},
globals: {
'artifacts': false,
'assert': false,
'contract': false,
'web3': false,
artifacts: false,
assert: false,
contract: false,
web3: false
},
extends:
[
Expand All @@ -20,13 +20,14 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
// The 'tsconfig.eslint.json' is needed to add all JavaScript files to the project
'project': ['./tsconfig.json', './tsconfig.eslint.json']
project: ['./tsconfig.json', './tsconfig.eslint.json']
},
ignorePatterns: [
'types/truffle-contracts',
'dist/'
],
rules: {
'no-console': 'off',
'no-console': 'off'
},
overrides: [
{
Expand All @@ -42,13 +43,14 @@ module.exports = {
// otherwise it will raise an error in every JavaScript file
files: ['*.ts'],
rules: {
'@typescript-eslint/prefer-ts-expect-error': 'off',
// allow using '${val}' with numbers, bool and null types
'@typescript-eslint/restrict-template-expressions': [
'error',
{
'allowNumber': true,
'allowBoolean': true,
'allowNullable': true
allowNumber: true,
allowBoolean: true,
allowNullable: true
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/GsnEip712Library.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "../interfaces/IRelayRecipient.sol";
import "../forwarder/Forwarder.sol";

/**
* Bridge Library to map GSN RelayRequest into a call of an Forwarder
* Bridge Library to map GSN RelayRequest into a call of a Forwarder
*/
library GsnEip712Library {

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@
"@typescript-eslint/parser": "3.0.2",
"chai-as-promised": "7.1.1",
"cors": "2.8.5",
"eslint": "6.8.0",
"eslint-config-standard": "14.1.0",
"eslint-config-standard-with-typescript": "14.0.0",
"eslint-plugin-import": "2.20.1",
"eslint-plugin-node": "10.0.0",
"eslint": "7.3.0",
"eslint-config-standard": "14.1.1",
"eslint-config-standard-with-typescript": "18.0.2",
"eslint-plugin-import": "2.21.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.0.1",
"ganache-cli": "6.9.1",
Expand Down
7 changes: 3 additions & 4 deletions src/cli/CommandsLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import ContractInteractor from '../relayclient/ContractInteractor'
import { GSNConfig } from '../relayclient/GSNConfigurator'
import HttpClient from '../relayclient/HttpClient'
import HttpWrapper from '../relayclient/HttpWrapper'
import { IPaymasterInstance } from '../../types/truffle-contracts'
import { GsnRequestType } from '../common/EIP712/TypedRequestData'

interface RegisterOptions {
Expand Down Expand Up @@ -103,7 +102,7 @@ export default class CommandsLogic {

async getPaymasterBalance (paymaster: Address): Promise<BN> {
const relayHub = await this.contractInteractor._createRelayHub(this.config.relayHubAddress)
return relayHub.balanceOf(paymaster)
return await relayHub.balanceOf(paymaster)
}

/**
Expand Down Expand Up @@ -183,7 +182,7 @@ export default class CommandsLogic {
if (fundTx.transactionHash == null) {
return {
success: false,
error: `Fund transaction reverted: ${_fundTx.toString()}`
error: `Fund transaction reverted: ${JSON.stringify(_fundTx)}`
}
}
await this.waitForRelay(options.relayUrl)
Expand Down Expand Up @@ -234,7 +233,7 @@ export default class CommandsLogic {
this.config.stakeManagerAddress = sInstance.options.address
this.config.relayHubAddress = rInstance.options.address

const res = await fInstance.methods.registerRequestType(
await fInstance.methods.registerRequestType(
GsnRequestType.typeName,
GsnRequestType.typeSuffix
).send(options)
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/gsn-paymaster-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const commander = gsnCommander(['h', 'n', 'm'])
const paymaster = getPaymasterAddress(commander.paymaster)

if (hub == null || paymaster == null) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Contracts not found: hub: ${hub} paymaster: ${paymaster} `)
}
const mnemonic = getMnemonic(commander.mnemonic)
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/gsn-paymaster-fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const commander = gsnCommander(['n', 'f', 'h', 'm'])
const paymaster = getPaymasterAddress(commander.paymaster)

if (hub == null || paymaster == null) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Contracts not found: hub: ${hub} paymaster: ${paymaster} `)
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function getEip712Signature (
} else {
dataToSign = typedRequestData
}
return new Promise((resolve, reject) => {
return await new Promise((resolve, reject) => {
let method
// @ts-ignore (the entire web3 typing is fucked up)
if (typeof web3.currentProvider.sendAsync === 'function') {
Expand Down Expand Up @@ -128,7 +128,7 @@ export function isSameAddress (address1: Address, address2: Address): boolean {
}

export async function sleep (ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms))
return await new Promise(resolve => setTimeout(resolve, ms))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/relayclient/AccountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class AccountManager {
// a) allow different implementations in the future, and
// b) allow spying on Account Manager in tests
async _signWithProvider (signedData: any): Promise<string> {
return getEip712Signature(
return await getEip712Signature(
this.web3,
signedData,
this.config.methodSuffix ?? '',
Expand Down
40 changes: 20 additions & 20 deletions src/relayclient/ContractInteractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,42 +121,42 @@ export default class ContractInteractor {

// eslint-disable-next-line @typescript-eslint/require-await
async _createKnowsForwarder (address: Address): Promise<IKnowForwarderAddressInstance> {
return this.IKnowForwarderAddress.at(address)
return await this.IKnowForwarderAddress.at(address)
}

// eslint-disable-next-line @typescript-eslint/require-await
async _createRecipient (address: Address): Promise<IRelayRecipientInstance> {
return this.IRelayRecipient.at(address)
return await this.IRelayRecipient.at(address)
}

// eslint-disable-next-line @typescript-eslint/require-await
async _createPaymaster (address: Address): Promise<IPaymasterInstance> {
return this.IPaymasterContract.at(address)
return await this.IPaymasterContract.at(address)
}

// eslint-disable-next-line @typescript-eslint/require-await
async _createRelayHub (address: Address): Promise<IRelayHubInstance> {
return this.IRelayHubContract.at(address)
return await this.IRelayHubContract.at(address)
}

// eslint-disable-next-line @typescript-eslint/require-await
async _createForwarder (address: Address): Promise<IForwarderInstance> {
return this.IForwarderContract.at(address)
return await this.IForwarderContract.at(address)
}

// eslint-disable-next-line @typescript-eslint/require-await
async _createStakeManager (address: Address): Promise<IStakeManagerInstance> {
return this.IStakeManager.at(address)
return await this.IStakeManager.at(address)
}

async getForwarder (recipientAddress: Address): Promise<Address> {
const recipient = await this._createKnowsForwarder(recipientAddress)
return recipient.getTrustedForwarder()
return await recipient.getTrustedForwarder()
}

async isTrustedForwarder (recipientAddress: Address, forwarder: Address): Promise<boolean> {
const recipient = await this._createRecipient(recipientAddress)
return recipient.isTrustedForwarder(forwarder)
return await recipient.isTrustedForwarder(forwarder)
}

async getSenderNonce (sender: Address, forwarderAddress: Address): Promise<IntString> {
Expand Down Expand Up @@ -218,12 +218,12 @@ export default class ContractInteractor {

async getPastEventsForHub (names: EventName[], extraTopics: string[], options: PastEventOptions): Promise<EventData[]> {
const relayHub = await this._createRelayHub(this.config.relayHubAddress)
return this._getPastEvents(relayHub.contract, names, extraTopics, options)
return await this._getPastEvents(relayHub.contract, names, extraTopics, options)
}

async getPastEventsForStakeManager (names: EventName[], extraTopics: string[], options: PastEventOptions): Promise<EventData[]> {
const stakeManager = await this._createStakeManager(this.config.stakeManagerAddress)
return this._getPastEvents(stakeManager.contract, names, extraTopics, options)
return await this._getPastEvents(stakeManager.contract, names, extraTopics, options)
}

// eslint-disable-next-line @typescript-eslint/require-await
Expand All @@ -238,44 +238,44 @@ export default class ContractInteractor {
}

async getPastLogs (options: PastLogsOptions): Promise<Log[]> {
return this.web3.eth.getPastLogs(options)
return await this.web3.eth.getPastLogs(options)
}

async getBalance (address: Address): Promise<string> {
return this.web3.eth.getBalance(address)
return await this.web3.eth.getBalance(address)
}

async getBlockNumber (): Promise<number> {
return this.web3.eth.getBlockNumber()
return await this.web3.eth.getBlockNumber()
}

async sendSignedTransaction (rawTx: string): Promise<TransactionReceipt> {
return this.web3.eth.sendSignedTransaction(rawTx)
return await this.web3.eth.sendSignedTransaction(rawTx)
}

async estimateGas (gsnTransactionDetails: GsnTransactionDetails): Promise<number> {
return this.web3.eth.estimateGas(gsnTransactionDetails)
return await this.web3.eth.estimateGas(gsnTransactionDetails)
}

async getGasPrice (): Promise<string> {
return this.web3.eth.getGasPrice()
return await this.web3.eth.getGasPrice()
}

async getTransactionCount (address: string, defaultBlock?: BlockNumber): Promise<number> {
// @ts-ignore (web3 does not define 'defaultBlock' as optional)
return this.web3.eth.getTransactionCount(address, defaultBlock)
return await this.web3.eth.getTransactionCount(address, defaultBlock)
}

async getTransaction (transactionHash: string): Promise<Transaction> {
return this.web3.eth.getTransaction(transactionHash)
return await this.web3.eth.getTransaction(transactionHash)
}

async getBlock (blockHashOrBlockNumber: BlockNumber): Promise<BlockTransactionString> {
return this.web3.eth.getBlock(blockHashOrBlockNumber)
return await this.web3.eth.getBlock(blockHashOrBlockNumber)
}

async getCode (address: string): Promise<string> {
return this.web3.eth.getCode(address)
return await this.web3.eth.getCode(address)
}

getChainId (): number {
Expand Down
1 change: 1 addition & 0 deletions src/relayclient/GsnTestEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class GsnTestEnvironmentClass {
if (registrationResult.success) {
console.log('In-process relay successfully registered:', JSON.stringify(registrationResult))
} else {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Failed to fund relay: ${registrationResult.error} : ${registrationResult?.transactions?.toString()}`)
}

Expand Down
2 changes: 1 addition & 1 deletion src/relayclient/HttpWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class HttpWrapper {
const errStr = ((typeof errData === 'string') ? errData : JSON.stringify(errData)).slice(0, LOGMAXLEN)
const errUrl = error.response != null ? error.response.config.url : error.address
console.log('got response:', errUrl, 'err=', errStr)
return Promise.reject(error)
return await Promise.reject(error)
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/relayclient/KnownRelaysManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ export const DefaultRelayScore = async function (relay: RelayRegisteredEventInfo
const transactionCost = baseFee + (gasLimit * gasPrice * (100 + pctFee)) / 100
let score = Math.max(Number.MAX_SAFE_INTEGER - transactionCost, 0)
score = score * Math.pow(0.9, failures.length)
return Promise.resolve(score)
return await Promise.resolve(score)
}

const activeManagerEvents = ['RelayServerRegistered', 'TransactionRelayed', 'TransactionRejectedByPaymaster', 'RelayWorkersAdded']

export interface IKnownRelaysManager {
refresh (): Promise<void>
refresh: () => Promise<void>

saveRelayFailure (lastErrorTime: number, relayManager: Address, relayUrl: string): void
saveRelayFailure: (lastErrorTime: number, relayManager: Address, relayUrl: string) => void

getRelaysSortedForTransaction (gsnTransactionDetails: GsnTransactionDetails): Promise<RelayInfoUrl[][]>
getRelaysSortedForTransaction: (gsnTransactionDetails: GsnTransactionDetails) => Promise<RelayInfoUrl[][]>

getRelayInfoForManagers (relayManagers: Set<Address>): Promise<RelayRegisteredEventInfo[]>
getRelayInfoForManagers: (relayManagers: Set<Address>) => Promise<RelayRegisteredEventInfo[]>
}

export default class KnownRelaysManager implements IKnownRelaysManager {
Expand Down
4 changes: 2 additions & 2 deletions src/relayclient/RelayClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { RelayInfo } from './types/RelayInfo'

// generate "approvalData" for a request. must return string-encoded bytes array
export const EmptyApprovalData: AsyncApprovalData = async (): Promise<PrefixedHexString> => {
return Promise.resolve('0x')
return await Promise.resolve('0x')
}

export const GasPricePingFilter: PingFilter = (pingResponse, gsnTransactionDetails) => {
Expand Down Expand Up @@ -270,7 +270,7 @@ export default class RelayClient {
let forwarderAddress = gsnTransactionDetails.forwarder ?? this.config.forwarderAddress
if (forwarderAddress !== constants.ZERO_ADDRESS) {
const recipientCode = await web3.eth.getCode(gsnTransactionDetails.to)
const isRecipientDeployed = recipientCode != '0x'
const isRecipientDeployed = recipientCode !== '0x'
if (!isRecipientDeployed) {
console.warn(`No IRelayRecipient code at ${gsnTransactionDetails.to}, proceeding without validating 'isTrustedForwarder'!
Unless you are using some counterfactual contract deployment technique the transaction will fail!`)
Expand Down
2 changes: 1 addition & 1 deletion src/relayclient/RelayProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class RelayProvider implements HttpProvider {
callback(new Error(message))
}
}, (reason: any) => {
const reasonStr = reason instanceof Error ? reason.toString() : JSON.stringify(reason)
const reasonStr = reason instanceof Error ? reason.message : JSON.stringify(reason)
callback(new Error(`Rejected relayTransaction call - should not happen. Reason: ${reasonStr}`))
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/relayclient/RelaySelectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default class RelaySelectionManager {
*/
async _raceToSuccess (relays: RelayInfoUrl[]): Promise<RaceResult> {
const errors: Map<string, Error> = new Map<string, Error>()
return new Promise((resolve) => {
return await new Promise((resolve) => {
relays.forEach((relay: RelayInfoUrl) => {
this._getRelayAddressPing(relay)
.then((winner: PartialRelayInfo) => {
Expand Down
4 changes: 2 additions & 2 deletions src/relayserver/KeyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { toHex } from 'web3-utils'
import { PrefixedHexString, Transaction } from 'ethereumjs-tx'

export class KeyManager {
private readonly hdkey: EthereumHDKey;
private readonly hdkey: EthereumHDKey
private _privateKeys: Record<PrefixedHexString, Buffer> = {}
private nonces: Record<string, number> = {};
private nonces: Record<string, number> = {}

/**
* @param count - # of addresses managed by this manager
Expand Down
Loading

0 comments on commit 704b4a5

Please sign in to comment.