Skip to content
This repository was archived by the owner on Dec 10, 2020. It is now read-only.

Commit a780c64

Browse files
committed
fix typescript-eslint/no-unnecessary-condition lint errors
1 parent d8a0f3b commit a780c64

File tree

17 files changed

+32
-53
lines changed

17 files changed

+32
-53
lines changed

browser/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ import { getLogger } from './logging'
4545
export function createNode(args: any) {
4646
const logger = getLogger({ loglevel: args.loglevel })
4747
const options = {
48-
common: new Common({ chain: args.network || 'mainnet' }),
48+
common: new Common({ chain: args.network ?? 'mainnet' }),
4949
servers: [new exports.Libp2pServer({ multiaddrs: [], ...args })],
50-
syncmode: args.syncmode || 'fast',
51-
db: level(args.db || 'ethereumjs'),
50+
syncmode: args.syncmode ?? 'fast',
51+
db: level(args.db ?? 'ethereumjs'),
5252
logger: logger,
5353
}
5454
return new exports.Node(options)

browser/libp2pnode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class Libp2pNode extends libp2p {
2626
bootstrap: {
2727
interval: 2000,
2828
enabled: options.bootnodes !== undefined,
29-
list: options.bootnodes || [],
29+
list: options.bootnodes ?? [],
3030
},
3131
},
3232
EXPERIMENTAL: {

lib/blockchain/chain.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class Chain extends EventEmitter {
105105
this.config = options.config
106106

107107
this.blockchain =
108-
options.blockchain ||
108+
options.blockchain ??
109109
new Blockchain({
110110
db: options.db,
111111
validateBlocks: false,
@@ -253,7 +253,7 @@ export class Chain extends EventEmitter {
253253
* @return {Promise<void>}
254254
*/
255255
async putBlocks(blocks: Block[]): Promise<void> {
256-
if (!blocks) {
256+
if (blocks.length === 0) {
257257
return
258258
}
259259
await this.open()
@@ -288,7 +288,7 @@ export class Chain extends EventEmitter {
288288
* @return {Promise<void>}
289289
*/
290290
async putHeaders(headers: BlockHeader[]): Promise<void> {
291-
if (!headers) {
291+
if (headers.length === 0) {
292292
return
293293
}
294294
await this.open()

lib/net/peer/libp2pnode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class Libp2pNode extends LibP2p {
3535
bootstrap: {
3636
interval: 2000,
3737
enabled: options.bootnodes !== undefined,
38-
list: options.bootnodes || [],
38+
list: options.bootnodes ?? [],
3939
},
4040
},
4141
dht: {

lib/net/peer/peer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class Peer extends events.EventEmitter {
120120
address: this.address,
121121
transport: this.transport,
122122
protocols: Array.from(this.bound.keys()),
123-
inbound: this.inbound || null,
123+
inbound: this.inbound,
124124
}
125125
return Object.entries(properties)
126126
.filter(([, value]) => value !== undefined && value !== null && value.toString() !== '')

lib/net/protocol/flowcontrol.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class FlowControl {
3636
* @param {number} bv latest buffer value
3737
*/
3838
handleReply(peer: Peer, bv: number) {
39-
const params = this.in.get(peer.id) || {}
39+
const params = this.in.get(peer.id) ?? {}
4040
params.ble = bv
4141
params.last = Date.now()
4242
this.in.set(peer.id, params)
@@ -54,7 +54,7 @@ export class FlowControl {
5454
const mrcReq = (peer.les as BoundProtocol).status.mrc[messageName].req
5555
const mrr = (peer.les as BoundProtocol).status.mrr
5656
const bl = (peer.les as BoundProtocol).status.bl
57-
const params = this.in.get(peer.id) || { ble: bl }
57+
const params = this.in.get(peer.id) ?? { ble: bl }
5858
if (params.last) {
5959
// recharge BLE at rate of MRR when less than BL
6060
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
@@ -77,7 +77,7 @@ export class FlowControl {
7777
*/
7878
handleRequest(peer: Peer, messageName: string, count: number): number {
7979
const now = Date.now()
80-
const params = this.out.get(peer.id) || {}
80+
const params = this.out.get(peer.id) ?? {}
8181
if (params.bv && params.last) {
8282
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
8383
params.bv = Math.min(params.bv + this.mrr * (now - params.last), this.bl)

lib/net/protocol/lesprotocol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ export class LesProtocol extends Protocol {
174174
headNum: new BN(status.headNum),
175175
genesisHash: status.genesisHash,
176176
serveHeaders: this.isServer,
177-
serveChainSince: status.serveChainSince && new BN(status.serveChainSince),
178-
serveStateSince: status.serveStateSince && new BN(status.serveStateSince),
177+
serveChainSince: status.serveChainSince ? new BN(status.serveChainSince) : undefined,
178+
serveStateSince: status.serveStateSince ? new BN(status.serveStateSince) : undefined,
179179
txRelay: !!status.txRelay,
180180
bl: status['flowControl/BL'] && new BN(status['flowControl/BL']).toNumber(),
181181
mrr: status['flowControl/MRR'] && new BN(status['flowControl/MRR']).toNumber(),

lib/rpc/modules/admin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ export class Admin {
3535
* @param {*} [cb] A function with an error object as the first argument and the result as the second
3636
*/
3737
async nodeInfo(params: any, cb: Function) {
38-
const rlpxInfo = this._node.server('rlpx').getRlpxInfo()
38+
const rlpxInfo = (this._node.server('rlpx') as any).getRlpxInfo()
3939
const { enode, id, ip, listenAddr, ports } = rlpxInfo
4040
const { discovery, listener } = ports
4141
const clientName = getClientVersion()
4242

4343
// TODO version not present in reference..
4444
// const ethVersion = Math.max.apply(Math, this._ethProtocol.versions)
4545
const latestHeader = (this._chain as any)._headers.latest
46-
const difficulty = latestHeader?.difficulty || 0 // should be number
46+
const difficulty = latestHeader?.difficulty ?? 0 // should be number
4747
const genesis = bufferToHex(this._chain.genesis.hash)
48-
const head = bufferToHex(latestHeader?.mixHash || null)
48+
const head = bufferToHex(latestHeader?.mixHash ?? null)
4949
const network = this._chain.networkId
5050

5151
const nodeInfo = {

lib/service/ethereumservice.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ export class EthereumService extends Service {
2121
public synchronizer: any
2222

2323
/**
24-
<<<<<<< HEAD
25-
* Create new ETH service
26-
* @param {Object} options constructor parameters
27-
* @param {Config} [options.config] Client configuration
28-
* @param {Chain} [options.chain] blockchain
29-
* @param {LevelDB} [options.db=null] blockchain database
30-
* @param {number} [options.timeout] protocol timeout
31-
* @param {number} [options.interval] sync retry interval
32-
*/
33-
=======
3424
* Create new ETH service
3525
* @param {Object} options constructor parameters
3626
* @param {Config} [options.config] Client configuration
@@ -39,23 +29,17 @@ export class EthereumService extends Service {
3929
* @param {number} [options.timeout] protocol timeout
4030
* @param {number} [options.interval] sync retry interval
4131
*/
42-
>>>>>>> Config -> syncmode, minPeers, maxPeers: horizontal integration
4332
constructor(options?: any) {
4433
options = { ...defaultOptions, ...options }
4534
super(options)
4635

4736
this.flow = new FlowControl(options)
48-
<<<<<<< HEAD
4937
this.chain = options.chain ?? new Chain(options)
50-
=======
51-
this.chain = options.chain || new Chain(options)
52-
>>>>>>> Config -> syncmode, minPeers, maxPeers: horizontal integration
5338
this.interval = options.interval
5439
this.timeout = options.timeout
5540
this.synchronizer = null
5641
}
5742

58-
5943
/**
6044
* Service name
6145
* @protected

lib/sync/fetcher/fetcher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export class Fetcher extends Readable {
168168
return false
169169
}
170170
const peer = this.peer()
171+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
171172
if (peer) {
172173
peer.idle = false
173174
this.in.remove()

0 commit comments

Comments
 (0)