Skip to content

Commit

Permalink
chore: add lint action
Browse files Browse the repository at this point in the history
  • Loading branch information
kid-icarus committed Dec 12, 2023
1 parent 2d6e23b commit e83d81a
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 9 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Tests
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review, review_requested]
branches:
- main
jobs:
run-tests:
if: github.event.pull_request.draft == false
name: Lint Packages
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Install
run: |
yarn install --no-lockfile
- name: Lint
run: yarn lint
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"pub": "lerna publish --yes",
"start:syncserver": "cross-env DEBUG='WebsocketServer' yarn workspace @automerge/example-sync-server start",
"repocheck": "manypkg check",
"lint": "lerna run lint",
"test": "vitest",
"test:log": "cross-env DEBUG='automerge-repo:*' vitest",
"test:coverage": "vitest --coverage",
Expand Down
1 change: 1 addition & 0 deletions packages/automerge-repo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"lint": "eslint --ext .ts src",
"watch": "npm-watch build",
"test:coverage": "c8 --reporter=lcov --reporter=html --reporter=text yarn test",
"test": "vitest",
Expand Down
2 changes: 1 addition & 1 deletion packages/automerge-repo/src/AutomergeUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const parseAutomergeUrl = (url: AutomergeUrl) => {
export const stringifyAutomergeUrl = (
arg: UrlOptions | DocumentId | BinaryDocumentId
) => {
let documentId =
const documentId =
arg instanceof Uint8Array || typeof arg === "string"
? arg
: "documentId" in arg
Expand Down
2 changes: 1 addition & 1 deletion packages/automerge-repo/src/RemoteHeadsSubscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export class RemoteHeadsSubscriptions extends EventEmitter<RemoteHeadsSubscripti
}

#isPeerSubscribedToDoc(peerId: PeerId, documentId: DocumentId) {
let subscribedDocs = this.#subscribedDocsByPeer.get(peerId)
const subscribedDocs = this.#subscribedDocsByPeer.get(peerId)
return subscribedDocs && subscribedDocs.has(documentId)
}

Expand Down
8 changes: 6 additions & 2 deletions packages/automerge-repo/src/Repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Repo extends EventEmitter<RepoEvents> {
}: DocHandleEncodedChangePayload<any>) => {
void storageSubsystem.saveDoc(handle.documentId, doc)
}
const debouncedSaveFn = handle.on(
handle.on(
"heads-changed",
throttle(saveFn, this.saveDebounceRate)
)
Expand Down Expand Up @@ -153,7 +153,8 @@ export class Repo extends EventEmitter<RepoEvents> {
// The network subsystem deals with sending and receiving messages to and from peers.

const myPeerMetadata: Promise<PeerMetadata> = new Promise(
async (resolve, reject) =>
// eslint-disable-next-line no-async-promise-executor -- TODO: fix
async (resolve) =>
resolve({
storageId: await storageSubsystem?.id(),
isEphemeral,
Expand Down Expand Up @@ -300,6 +301,9 @@ export class Repo extends EventEmitter<RepoEvents> {
handler = this.#throttledSaveSyncStateHandlers[storageId] = throttle(
({ documentId, syncState }: SyncStateMessage) => {
this.storageSubsystem!.saveSyncState(documentId, storageId, syncState)
.catch(err => {
console.error("error saving sync state", { err })
})
},
this.saveDebounceRate
)
Expand Down
2 changes: 1 addition & 1 deletion packages/automerge-repo/src/helpers/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const throttle = <F extends (...args: Parameters<F>) => ReturnType<F>>(
return function (...args: Parameters<F>) {
clearTimeout(timeout)
timeout = setTimeout(() => {
fn.apply(null, args)
fn(...args)
}, rate)
}
}
2 changes: 1 addition & 1 deletion packages/automerge-repo/src/helpers/throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const throttle = <F extends (...args: Parameters<F>) => ReturnType<F>>(
wait = lastCall + delay - Date.now()
clearTimeout(timeout)
timeout = setTimeout(() => {
fn.apply(null, args)
fn(...args)
lastCall = Date.now()
}, wait)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/automerge-repo/src/network/NetworkSubsystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
isEphemeralMessage,
isValidRepoMessage,
} from "./messages.js"
import { StorageId } from "../storage/types.js"

type EphemeralMessageSource = `${PeerId}:${SessionId}`

Expand Down Expand Up @@ -108,6 +107,8 @@ export class NetworkSubsystem extends EventEmitter<NetworkSubsystemEvents> {

this.peerMetadata.then(peerMetadata => {
networkAdapter.connect(this.peerId, peerMetadata)
}).catch(err => {
this.#log("error connecting to network", err)
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/automerge-repo/src/storage/StorageSubsystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class StorageSubsystem {
}

async id(): Promise<StorageId> {
let storedId = await this.#storageAdapter.load(["storage-adapter-id"])
const storedId = await this.#storageAdapter.load(["storage-adapter-id"])

let id: StorageId
if (storedId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import debug from "debug"
import { DocHandle } from "../DocHandle.js"
import { stringifyAutomergeUrl } from "../AutomergeUrl.js"
import { Repo } from "../Repo.js"
import { DocMessage, RepoMessage } from "../network/messages.js"
import { DocMessage } from "../network/messages.js"
import { DocumentId, PeerId } from "../types.js"
import { DocSynchronizer } from "./DocSynchronizer.js"
import { Synchronizer } from "./Synchronizer.js"
Expand Down
4 changes: 4 additions & 0 deletions packages/automerge-repo/src/synchronizer/DocSynchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export class DocSynchronizer extends Synchronizer {
if (!pendingCallbacks) {
this.#onLoadSyncState(peerId).then(syncState => {
this.#initSyncState(peerId, syncState ?? A.initSyncState())
}).catch(err => {
this.#log(`Error loading sync state for ${peerId}: ${err}`)
})
pendingCallbacks = this.#pendingSyncStateCallbacks[peerId] = []
}
Expand Down Expand Up @@ -264,6 +266,8 @@ export class DocSynchronizer extends Synchronizer {
if (doc) {
this.#sendSyncMessage(peerId, doc)
}
}).catch(err => {
this.#log(`Error loading doc for ${peerId}: ${err}`)
})
})
})
Expand Down

0 comments on commit e83d81a

Please sign in to comment.