Skip to content

Commit

Permalink
Fix linter errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
saul-jb committed Jul 23, 2024
1 parent c6d9787 commit 28eecf3
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 47 deletions.
2 changes: 2 additions & 0 deletions packages/benchmarks/src/utils/run-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export default async (path: string, options: { persistent?: boolean } = {}): Pro
setTimeout(() => {
forceQuit().finally(() => {
promise.reject(new Error('process did not exit cleanly'))
}).catch(() => {
promise.reject(new Error('process did not exit cleanly'))
})
}, 3000)

Expand Down
7 changes: 6 additions & 1 deletion packages/daemon/src/modules/filesystem/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from 'assert/strict'
import Path from 'path'
import { CID } from 'multiformats/cid'
import { DATA_KEY, EncodedEntry, type Entry } from './interface.js'
Expand All @@ -9,7 +10,11 @@ export const encodeEntry = (entry: Entry): NonNullable<EncodedEntry> => {
}

// Parse will strip foreign keys...
return EncodedEntry.parse(ee)!
const stripped = EncodedEntry.parse(ee)

assert(stripped != null)

return stripped
}

export const decodeEntry = (entry: NonNullable<EncodedEntry>): Entry => ({
Expand Down
7 changes: 6 additions & 1 deletion packages/daemon/src/modules/revisions/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from 'assert/strict'
import Path from 'path'
import { CID } from 'multiformats/cid'
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
Expand All @@ -11,7 +12,11 @@ export const encodeEntry = (entry: Entry): NonNullable<EncodedEntry> => {
}

// Parse will strip foreign keys...
return EncodedEntry.parse(ee)!
const stripped = EncodedEntry.parse(ee)

assert(stripped != null)

return stripped
}

export const decodeEntry = (entry: NonNullable<EncodedEntry>): Entry => ({
Expand Down
7 changes: 6 additions & 1 deletion packages/daemon/src/modules/scheduler/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import assert from 'assert/strict'
import { type Entry, EncodedEntry } from './interface.js'

export const encodeEntry = (entry: Entry): NonNullable<EncodedEntry> => {
// Parse will strip foreign keys...
return EncodedEntry.parse(entry)!
const stripped = EncodedEntry.parse(entry)

assert(stripped != null)

return stripped
}

export const decodeEntry = (encodedEntry: NonNullable<EncodedEntry>): Entry => ({
Expand Down
4 changes: 2 additions & 2 deletions packages/daemon/test/modules/groups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('groups', () => {
const { components } = await create()
const group = await createGroup(components, 'test')

assert(group)
assert(group != null)

await components.stop()
})
Expand Down Expand Up @@ -225,7 +225,7 @@ describe('groups', () => {

const database = components[0].components.groups.get(group)

assert(database)
assert(database != null)
assert.equal(database.manifest.name, name)

client.stop()
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/test/connectivity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('connectivity', () => {
const data: string[] = await runClient(nodes[0], 'addresses')
const tcp = data.find(d => d.startsWith('/ip4/127.0.0.1/tcp'))

assert(tcp)
assert(tcp != null)
})

it('displays no connections on startup', async () => {
Expand All @@ -34,7 +34,7 @@ describe('connectivity', () => {
const peerAData: string[] = await runClient(nodes[0], 'addresses')
const tcp = peerAData.find(d => d.startsWith('/ip4/127.0.0.1/tcp'))

assert(tcp)
assert(tcp != null)

const peerBData = await runClient(nodes[1], 'connect', tcp)

Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/test/group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('group', () => {
const peerAData: string[] = await runClient(nodes[0], 'addresses')
const tcp = peerAData.find(d => d.startsWith('/ip4/127.0.0.1/tcp'))

assert(tcp)
assert(tcp != null)

const peerBData = await runClient(nodes[1], 'connect', tcp)

Expand Down
24 changes: 12 additions & 12 deletions packages/e2e-tests/test/revisions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('revisions', () => {

const response = await runClient(node, 'import', group, dataFile.path, virtualDir)

assert(response.success)
assert(response.success === true)
})

after(async () => {
Expand All @@ -30,7 +30,7 @@ describe('revisions', () => {
it('has 1 revision after importing a file', async () => {
const response = await runClient(node, 'revisions', group, virtualDir)

assert(response)
assert(response != null)
assert(Array.isArray(response))
assert.equal(response.length, 1)
assert.equal(response[0].sequence, 0)
Expand All @@ -39,13 +39,13 @@ describe('revisions', () => {
it("has 0 revisions after overwrite with strategy 'none'", async () => {
const add = await runClient(node, 'import', group, dataFile.path, virtualDir, '--revisionStrategy', 'none')

assert(add.success)
assert(add.success === true)

const response = await runClient(node, 'revisions', group, virtualDir)

await new Promise(resolve => setTimeout(resolve, 3000))

assert(response)
assert(response != null)
assert(Array.isArray(response))
assert.equal(response.length, 0)
// assert.equal(response[0].sequence, 1)
Expand All @@ -54,11 +54,11 @@ describe('revisions', () => {
it("has 1 revisions after overwrite with strategy 'log'", async () => {
const add = await runClient(node, 'import', group, dataFile.path, virtualDir, '--revisionStrategy', 'log')

assert(add.success)
assert(add.success === true)

const response = await runClient(node, 'revisions', group, virtualDir)

assert(response)
assert(response != null)
assert(Array.isArray(response))
assert.equal(response.length, 1)
assert.equal(response[0].sequence, 2)
Expand All @@ -67,11 +67,11 @@ describe('revisions', () => {
it("has 2 revisions after overwrite with strategy 'all'", async () => {
const add = await runClient(node, 'import', group, dataFile.path, virtualDir, '--revisionStrategy', 'all')

assert(add.success)
assert(add.success === true)

const response = await runClient(node, 'revisions', group, virtualDir)

assert(response)
assert(response != null)
assert(Array.isArray(response))
assert.equal(response.length, 2)
assert.equal(response[0].sequence, 2)
Expand All @@ -81,11 +81,11 @@ describe('revisions', () => {
it("reduces to 1 revision after overwrite with strategy 'log'", async () => {
const add = await runClient(node, 'import', group, dataFile.path, virtualDir, '--revisionStrategy', 'log')

assert(add.success)
assert(add.success === true)

const response = await runClient(node, 'revisions', group, virtualDir)

assert(response)
assert(response != null)
assert(Array.isArray(response))
assert.equal(response.length, 1)
assert.equal(response[0].sequence, 2)
Expand All @@ -94,11 +94,11 @@ describe('revisions', () => {
it("reduces to 0 revisions after overwrite with strategy 'none'", async () => {
const add = await runClient(node, 'import', group, dataFile.path, virtualDir, '--revisionStrategy', 'none')

assert(add.success)
assert(add.success === true)

const response = await runClient(node, 'revisions', group, virtualDir)

assert(response)
assert(response != null)
assert(Array.isArray(response))
assert.equal(response.length, 0)
})
Expand Down
28 changes: 14 additions & 14 deletions packages/e2e-tests/test/synchronization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ describe('synchronization', () => {

group = (await runClient(nodes[0], 'create-group', 'test')).group

assert(tcp)
assert(tcp != null)

for (let i = 1; i < nodes.length; i++) {
const response = await runClient(nodes[i], 'connect', tcp)

assert(response.success)
assert(response.success === true)
}
})

Expand All @@ -43,23 +43,23 @@ describe('synchronization', () => {
virtualPath
)

assert(addRes.success)
assert(addRes.success === true)

const joinRes = await runClient(nodes[1], 'join-group', group)

assert(joinRes.success)
assert(joinRes.success === true)

// Ensure it syncs...
const sync = await runClient(nodes[1], 'sync')

assert(sync.success)
assert(sync.success === true)

const listRes = await runClient(nodes[1], 'list')

assert(listRes)
assert(listRes != null)
assert.equal(typeof listRes, 'object')
assert(listRes.items)
assert(listRes.total)
assert(listRes.items != null)
assert(listRes.total != null)
assert(Array.isArray(listRes.items))
assert.equal(listRes.items.length, 1)
assert.equal(listRes.items[0].cid, addRes.imports[0].cid)
Expand All @@ -78,25 +78,25 @@ describe('synchronization', () => {
virtualPath
)

assert(addRes.success)
assert(addRes.success === true)

// Ensure it syncs...
const sync = await runClient(nodes[1], 'sync')

assert(sync.success)
assert(sync.success === true)

const listRes = await runClient(nodes[1], 'list')

assert(listRes)
assert(listRes != null)
assert.equal(typeof listRes, 'object')
assert(listRes.items)
assert(listRes.total)
assert(listRes.items != null)
assert(listRes.total != null)
assert(Array.isArray(listRes.items))
assert.equal(listRes.items.length, 2)

const item = listRes.items.find((i: { cid: string }) => i.cid === addRes.imports[0].cid)

assert(item)
assert(item != null)
assert.equal(item.group, group)
assert.equal(item.path, virtualPath)
})
Expand Down
2 changes: 2 additions & 0 deletions packages/e2e-tests/test/utils/run-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export default async (name: string): Promise<{ start(): Promise<void>, stop(): P
setTimeout(() => {
forceQuit().finally(() => {
promise.reject(new Error('process did not exit cleanly'))
}).catch(() => {
promise.reject(new Error('process did not exit cleanly'))
})
}, 3000)

Expand Down
12 changes: 6 additions & 6 deletions packages/helia-pin-manager/test/pin-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('pin manager', () => {
it('constructs', () => {
const pinManager = new PinManager(components)

assert(pinManager)
assert(pinManager != null)
})

it('all returns all the pins', async () => {
Expand All @@ -108,7 +108,7 @@ describe('pin manager', () => {
const pins = await pm.all()

for (const pin of pins) {
assert(data.pins.find(p => p.cid.equals(pin.cid)))
assert(data.pins.find(p => p.cid.equals(pin.cid)) != null)
}
})

Expand Down Expand Up @@ -189,7 +189,7 @@ describe('pin manager', () => {
const raw = await pinsDatastore.get(new Key(root.toString()))
const data = cborg.decode(raw)

assert(data)
assert(data != null)
})

it('adds all the items in the dag as blocks', async () => {
Expand All @@ -202,7 +202,7 @@ describe('pin manager', () => {
assert.equal(pairs.length, Object.values(dag).length)

for (const { key } of pairs) {
assert(dag.find(b => b.equals(CID.parse(key.baseNamespace()))))
assert(dag.find(b => b.equals(CID.parse(key.baseNamespace()))) != null)
}
})

Expand Down Expand Up @@ -244,7 +244,7 @@ describe('pin manager', () => {
const raw = await pinsDatastore.get(new Key(root.toString()))
const data = cborg.decode(raw)

assert(data)
assert(data != null)
assert.equal(data.status, 'DOWNLOADING')
})

Expand All @@ -269,7 +269,7 @@ describe('pin manager', () => {
const pin = await pinsDatastore.get(new Key(root.toString()))

assert.equal(downloads.length, 0)
assert(pin)
assert(pin != null)
})

it('emits pins:adding event', async () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/key-manager/test/key-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ describe('key manager', () => {
const peerId = await d.keyManager.getPeerId()
const key = d.keyData.key.deriveHardened(0)

assert.deepEqual(new Uint8Array(key.privateKey as Buffer), (peerId.privateKey as Uint8Array).slice(4))
assert(key.privateKey != null)
assert(peerId.privateKey != null)

assert.deepEqual(new Uint8Array(key.privateKey), (peerId.privateKey).slice(4))
}))
})

Expand Down
8 changes: 4 additions & 4 deletions packages/key-manager/test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('nameToPath', () => {
while (paths.length > 0) {
const item = paths.pop()

assert(item)
assert(item != null)
assert(!paths.includes(item))
}
})
Expand All @@ -51,7 +51,7 @@ describe('nameToPath', () => {
const nums = path.slice(2).split('/').map(s => Number.parseInt(s))

for (const num of nums) {
assert(num)
assert(num != null)
assert(!Number.isNaN(num))
assert(num > 0)
}
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('nameToPath', () => {
describe('decodeKey', () => {
it('decodes valid keys', () => {
for (const { key } of data) {
assert(decodeKey(key))
assert(decodeKey(key) != null)
}
})
})
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('parseKeyData', () => {
await Promise.all(data.map(async ({ key, psk }) => {
const keyData = parseKeyData({ key, psk })

assert(keyData)
assert(keyData != null)
assert.deepEqual(keyData.key, decodeKey(key))
assert.deepEqual(keyData.psk, uint8ArrayFromString(psk))
}))
Expand Down
2 changes: 1 addition & 1 deletion packages/manual-block-broker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ManualBlockBroker implements BlockBroker {

signal?.addEventListener('abort', () => {
this.promises.delete(cid.toString())
promise.reject('operation aborted')
promise.reject(new Error('operation aborted'))
})

this.promises.set(cid.toString(), promise)
Expand Down
Loading

0 comments on commit 28eecf3

Please sign in to comment.