Skip to content

Commit

Permalink
fix: floating promises and add no-floating-promises to eslint-config-…
Browse files Browse the repository at this point in the history
…w3up (#1198)

Motivation:
* i want https://typescript-eslint.io/rules/no-floating-promises/
* it would have caught a floating promise on `addSpace` that alan just
reported
  • Loading branch information
gobengo authored Nov 29, 2023
1 parent 85e4b87 commit 1b8c5aa
Show file tree
Hide file tree
Showing 25 changed files with 75 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/access-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ on:
- main
paths:
- 'packages/access-client/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/access-client.yml'
- 'pnpm-lock.yaml'
pull_request:
paths:
- 'packages/access-client/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/access-client.yml'
- 'pnpm-lock.yaml'
jobs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/capabilities.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ on:
- main
paths:
- 'packages/capabilities/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/capabilities.yml'
- 'pnpm-lock.yaml'
pull_request:
paths:
- 'packages/capabilities/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/capabilities.yml'
- 'pnpm-lock.yaml'
jobs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/did-mailto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:
- main
paths:
- 'packages/did-mailto/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/did-mailto.yml'
- 'pnpm-lock.yaml'
pull_request:
paths:
- 'packages/did-mailto/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/did-mailto.yml'
- 'pnpm-lock.yaml'
jobs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/filecoin-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ on:
- main
paths:
- 'packages/filecoin-api/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/filecoin-api.yml'
- 'pnpm-lock.yaml'
- '.env.tpl'
pull_request:
paths:
- 'packages/filecoin-api/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/filecoin-api.yml'
- 'pnpm-lock.yaml'
- '.env.tpl'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/filecoin-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ on:
- main
paths:
- 'packages/filecoin-client/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/filecoin-client.yml'
- 'pnpm-lock.yaml'
pull_request:
paths:
- 'packages/filecoin-client/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/filecoin-client.yml'
- 'pnpm-lock.yaml'
jobs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/upload-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ on:
- main
paths:
- 'packages/upload-api/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/upload-api.yml'
- 'pnpm-lock.yaml'
- '.env.tpl'
pull_request:
paths:
- 'packages/upload-api/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/upload-api.yml'
- 'pnpm-lock.yaml'
- '.env.tpl'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/upload-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ on:
- main
paths:
- 'packages/upload-client/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/client.yml'
- 'pnpm-lock.yaml'
pull_request:
paths:
- 'packages/upload-client/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/client.yml'
- 'pnpm-lock.yaml'
jobs:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/w3up-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:
- main
paths:
- 'packages/w3up-client/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/w3up-client.yml'
- 'pnpm-lock.yaml'
pull_request:
paths:
- 'packages/w3up-client/**'
- 'packages/eslint-config-w3up/**'
- '.github/workflows/w3up-client.yml'
- 'pnpm-lock.yaml'
jobs:
Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ export async function addSpacesFromDelegations(agent, delegations) {
for (const [did, value] of Object.entries(allows)) {
// If we discovered a delegation to any DID, we add it to the spaces list.
if (did.startsWith('did:key') && Object.keys(value).length > 0) {
data.addSpace(/** @type {API.DID} */ (did), {
await data.addSpace(/** @type {API.DID} */ (did), {
name: '',
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class OwnedSpace {

const proof = await createAuthorization(this, { agent })
await agent.importSpaceFromDelegation(proof)
agent.setCurrentSpace(this.did())
await agent.setCurrentSpace(this.did())

return { ok: {} }
}
Expand Down
4 changes: 2 additions & 2 deletions packages/access-client/test/agent-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('AgentData', () => {
},
],
})
agentData.addDelegation(delegation)
await agentData.addDelegation(delegation)

const mapIssuerToSession = new Map()
for (const service of services) {
Expand All @@ -61,7 +61,7 @@ describe('AgentData', () => {
with: service.did(),
nb: { proof: delegation.cid },
})
agentData.addDelegation(session)
await agentData.addDelegation(session)
mapIssuerToSession.set(service.did(), session)
}

Expand Down
8 changes: 4 additions & 4 deletions packages/access-client/test/agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ describe('Agent', function () {
with: service.did(),
nb: { proof: delegation.cid },
})
agent.addProof(delegation)
agent.addProof(session)
await agent.addProof(delegation)
await agent.addProof(session)
}
const proofsForService = agent.proofs([
{ can: 'provider/add', with: account },
Expand Down Expand Up @@ -500,8 +500,8 @@ describe('Agent', function () {
with: service.did(),
nb: { proof: delegation.cid },
})
agent.addProof(delegation)
agent.addProof(session)
await agent.addProof(delegation)
await agent.addProof(session)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ describe('IndexedDB store', () => {
expiration: Infinity,
})

data0.addDelegation(del0, { audience: { name: 'test', type: 'device' } })
await data0.addDelegation(del0, {
audience: { name: 'test', type: 'device' },
})
await store.save(data0.export())

const exportData1 = await store.load()
Expand Down
18 changes: 9 additions & 9 deletions packages/did-mailto/test/did-mailto.spec.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import * as assert from 'assert'
import * as didMailto from '../src/index.js'

describe('did-mailto', () => {
testDidMailto(didMailto, async (name, test) => it(name, test))
describe('did-mailto', async () => {
await testDidMailto(didMailto, async (name, test) => it(name, test))
})

/**
* @param {typeof didMailto} didMailto - did-mailto module to test
* @param {import("./test-types.js").TestAdder} test - function to call to add a named test
*/
function testDidMailto(didMailto, test) {
test('module is an object', async () => {
async function testDidMailto(didMailto, test) {
await test('module is an object', async () => {
assert.equal(typeof didMailto, 'object')
})
for (const { email, did } of examples()) {
test(`fromEmail("${email}")`, async () => {
await test(`fromEmail("${email}")`, async () => {
assert.deepStrictEqual(didMailto.fromEmail(email), did)
})
test(`toEmail("${did}")`, async () => {
await test(`toEmail("${did}")`, async () => {
assert.deepStrictEqual(didMailto.toEmail(did), email)
})
test(`toEmail(fromEmail("${email}"))`, async () => {
await test(`toEmail(fromEmail("${email}"))`, async () => {
assert.deepStrictEqual(
didMailto.toEmail(didMailto.fromEmail(email)),
email
)
})
test(`fromEmail(toEmail("${did}"))`, async () => {
await test(`fromEmail(toEmail("${did}"))`, async () => {
assert.deepStrictEqual(didMailto.fromEmail(didMailto.toEmail(did)), did)
})
}
for (const email of validEmailAddresses()) {
test(`email("${email}")`, async () => {
await test(`email("${email}")`, async () => {
assert.doesNotThrow(() => didMailto.email(email), 'can parse to email')
})
}
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-config-w3up/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'plugin:jsdoc/recommended',
],
parserOptions: {
EXPERIMENTAL_useProjectService: true,
},
rules: {
"@typescript-eslint/no-floating-promises": "error",
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/ban-ts-comment': 'off',

Expand Down
12 changes: 12 additions & 0 deletions packages/eslint-config-w3up/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src", "test", "index.js"],
"exclude": ["**/node_modules/**", "dist"],
"references": [],
"typedocOptions": {
"entryPoints": ["."]
}
}
4 changes: 2 additions & 2 deletions packages/upload-api/test/access-client-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export const test = {
await deviceA.importSpaceFromDelegation(auth)

// make space current
deviceA.setCurrentSpace(spaceCreation.did())
await deviceA.setCurrentSpace(spaceCreation.did())

const recovery = await spaceCreation.createRecovery(account.did())
const delegateResult = await AgentAccess.delegate(deviceA, {
Expand Down Expand Up @@ -395,7 +395,7 @@ export const test = {
const { account, agent, mail } = await setup(context)

// fire off request
requestAccess(agent, account, [{ can: '*' }])
await requestAccess(agent, account, [{ can: '*' }])
const claimed = pollAccessClaimUntil(
delegationsIncludeSessionProof,
agent,
Expand Down
2 changes: 1 addition & 1 deletion packages/upload-api/test/handlers/plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const test = {
'an account can get plan information': async (assert, context) => {
const account = 'did:mailto:example.com:alice'
const product = 'did:web:test.web3.storage'
context.plansStorage.set(account, product)
await context.plansStorage.set(account, product)
const connection = connect({
id: context.id,
channel: createServer(context),
Expand Down
4 changes: 2 additions & 2 deletions packages/upload-api/test/handlers/provider-add.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe(`provider/add`, () => {

assert.ok(addW3Storage.out.error, 'Provider already added to this space')
} finally {
cleanupContext(context)
await cleanupContext(context)
}
})

Expand Down Expand Up @@ -289,7 +289,7 @@ describe(`provider/add`, () => {
`Account identified by ${account.did()} has not selected a payment plan`
)
} finally {
cleanupContext(context)
await cleanupContext(context)
}
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/upload-client/test/store.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('Store.add', () => {
channel: server,
})

assert.rejects(
await assert.rejects(
Store.add(
{ issuer: agent, with: space.did(), proofs, audience: serviceSigner },
car,
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('Store.add', () => {
channel: server,
})

assert.rejects(
await assert.rejects(
Store.add(
{ issuer: agent, with: space.did(), proofs, audience: serviceSigner },
car,
Expand Down
4 changes: 2 additions & 2 deletions packages/w3up-client/test/capability/filecoin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('FilecoinClient', () => {

const space = await alice.createSpace('test')
const auth = await space.createAuthorization(alice)
alice.addSpace(auth)
await alice.addSpace(auth)
await alice.setCurrentSpace(space.did())

const [cargo] = await randomCargo(1, 100)
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('FilecoinClient', () => {

const space = await alice.createSpace('test')
const auth = await space.createAuthorization(alice)
alice.addSpace(auth)
await alice.addSpace(auth)
await alice.setCurrentSpace(space.did())

const res = await alice.capability.filecoin.info(cargo.link)
Expand Down
2 changes: 1 addition & 1 deletion packages/w3up-client/test/capability/space.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('SpaceClient', () => {
access: { 'space/info': {} },
expiration: Infinity,
})
alice.addSpace(auth)
await alice.addSpace(auth)
await alice.setCurrentSpace(space.did())

const info = await alice.capability.space.info(space.did())
Expand Down
8 changes: 4 additions & 4 deletions packages/w3up-client/test/capability/store.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('StoreClient', () => {

const space = await alice.createSpace('test')
const auth = await space.createAuthorization(alice)
alice.addSpace(auth)
await alice.addSpace(auth)
await alice.setCurrentSpace(space.did())

const car = await randomCAR(128)
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('StoreClient', () => {

const space = await alice.createSpace('test')
const auth = await space.createAuthorization(alice)
alice.addSpace(auth)
await alice.addSpace(auth)
await alice.setCurrentSpace(space.did())

const res = await alice.capability.store.list()
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('StoreClient', () => {

const space = await alice.createSpace('test')
const auth = await space.createAuthorization(alice)
alice.addSpace(auth)
await alice.addSpace(auth)
await alice.setCurrentSpace(space.did())

await alice.capability.store.remove((await randomCAR(128)).cid)
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('StoreClient', () => {

const space = await alice.createSpace('test')
const auth = await space.createAuthorization(alice)
alice.addSpace(auth)
await alice.addSpace(auth)
await alice.setCurrentSpace(space.did())

const result = await alice.capability.store.get(car.cid)
Expand Down
Loading

0 comments on commit 1b8c5aa

Please sign in to comment.