Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
fix lint problems
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Nov 30, 2020
1 parent f4bddd4 commit f4c6493
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 13 deletions.
2 changes: 2 additions & 0 deletions benchmarks/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const run = async (): Promise<void> => {
}
}

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (SYMMETRIC) {
await trie.put(key, key)
genRoot()
Expand All @@ -36,6 +37,7 @@ const run = async (): Promise<void> => {

const go = async () => {
const testName = `benchmarks/random.ts | rounds: ${ROUNDS}, ERA_SIZE: ${ERA_SIZE}, ${
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
SYMMETRIC ? 'sys' : 'rand'
}`
console.time(testName)
Expand Down
11 changes: 8 additions & 3 deletions src/baseTrie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class Trie {
*/
async put(key: Buffer, value: Buffer): Promise<void> {
// If value is empty, delete
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!value || value.toString() === '') {
return await this.del(key)
}
Expand Down Expand Up @@ -194,7 +195,7 @@ export class Trie {
resolve({ node: null, remaining: keyRemainder, stack })
} else {
// keys match, continue search
await walkController.allChildren(node, keyProgress)
walkController.allChildren(node, keyProgress)
}
}
}
Expand Down Expand Up @@ -383,8 +384,10 @@ export class Trie {
stack: TrieNode[]
) => {
// branchNode is the node ON the branch node not THE branch node
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!parentNode || parentNode instanceof BranchNode) {
// branch->?
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (parentNode) {
stack.push(parentNode)
}
Expand Down Expand Up @@ -588,10 +591,12 @@ export class Trie {
async batch(ops: BatchDBOp[]): Promise<void> {
for (const op of ops) {
if (op.type === 'put') {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!op.value) {
throw new Error('Invalid batch db operation')
}
await this.put(op.key, op.value)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
} else if (op.type === 'del') {
await this.del(op.key)
}
Expand Down Expand Up @@ -689,7 +694,7 @@ export class Trie {
async _findDbNodes(onFound: FoundNodeFunction): Promise<void> {
const outerOnFound: FoundNodeFunction = async (nodeRef, node, key, walkController) => {
if (isRawNode(nodeRef)) {
await walkController.allChildren(node, key)
walkController.allChildren(node, key)
} else {
onFound(nodeRef, node, key, walkController)
}
Expand All @@ -715,7 +720,7 @@ export class Trie {
onFound(nodeRef, node, fullKey, walkController)
} else {
// keep looking for value nodes
await walkController.allChildren(node, key)
walkController.allChildren(node, key)
}
}
await this.walkTrie(this.root, outerOnFound)
Expand Down
3 changes: 3 additions & 0 deletions src/checkpointTrie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class CheckpointTrie extends BaseTrie {
await this.lock.wait()

this._checkpoints.pop()
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!this.isCheckpoint) {
await this._exitCpMode(true)
}
Expand All @@ -71,8 +72,10 @@ export class CheckpointTrie extends BaseTrie {
*/
async revert(): Promise<void> {
await this.lock.wait()
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (this.isCheckpoint) {
this.root = this._checkpoints.pop()!
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!this.isCheckpoint) {
await this._exitCpMode(false)
}
Expand Down
2 changes: 1 addition & 1 deletion src/readStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class TrieReadStream extends Readable {
key: nibblesToBuffer(key),
value: node.value,
})
await walkController.allChildren(node, key)
walkController.allChildren(node, key)
})
this.push(null)
}
Expand Down
1 change: 1 addition & 0 deletions src/scratch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class ScratchDB extends DB {
}

// If not found, try searching upstream db
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!value && this._upstream._leveldb) {
try {
value = await this._upstream._leveldb.get(key, ENCODING_OPTS)
Expand Down
2 changes: 1 addition & 1 deletion src/scratchReadStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ScratchReadStream extends Readable {
key: nodeRef,
value: node.serialize(),
})
await walkController.allChildren(node, key)
walkController.allChildren(node, key)
})
this.push(null)
}
Expand Down
1 change: 1 addition & 0 deletions src/secure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class SecureTrie extends CheckpointTrie {
* @param value
*/
async put(key: Buffer, val: Buffer): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!val || val.toString() === '') {
await this.del(key)
} else {
Expand Down
22 changes: 14 additions & 8 deletions src/util/walkStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,21 @@ export default class WalkStrategy {
await strategy.startWalk(root)
}

private startWalk(root: Buffer): Promise<void> {
return new Promise(async (resolve) => {
private async startWalk(root: Buffer): Promise<void> {
return await new Promise((resolve) => {
this.resolve = resolve
const node = await this.trie._lookupNode(root)
if (!node) {
this.resolve()
} else {
this.processNode(root, node as TrieNode, [])
}
this.trie
._lookupNode(root)
.then((node) => {
if (!node) {
this.resolve()
} else {
this.processNode(root, node as TrieNode, [])
}
})
.catch((e) => {
throw e
})
})
}

Expand Down

0 comments on commit f4c6493

Please sign in to comment.