Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get eslint working with GitHub actions #262

Merged
merged 13 commits into from
Jan 19, 2024
54 changes: 54 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const OFF = 0
const WARN = 1
const ERROR = 2
const NEVER = "never"
const ALWAYS = "always"

module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
],
ignorePatterns: [
"**/*.d.ts",
"**/*.config.ts",
"**/fuzz.ts",
"examples/**/*",
"**/test/*",
"**/dist/*",
"**/node_modules/*",
".eslintrc.cjs",
],
overrides: [
{
env: { node: true },
files: [".eslintrc.{js,cjs}"],
parserOptions: { sourceType: "script" },
},
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["./packages/*/tsconfig.json"],
ecmaVersion: "latest",
sourceType: "module",
},
plugins: ["@typescript-eslint"],
rules: {
semi: [ERROR, NEVER],
"import/extensions": OFF,
"lines-between-class-members": OFF,
"@typescript-eslint/no-floating-promises": ERROR,
"@typescript-eslint/no-empty-function": OFF,
"no-param-reassign": OFF,
"no-use-before-define": OFF,
"@typescript-eslint/no-non-null-assertion": OFF,
"@typescript-eslint/no-explicit-any": OFF,
},
root: true,
}
14 changes: 9 additions & 5 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests
name: Lint
on:
push:
branches:
Expand All @@ -15,14 +15,18 @@ jobs:
steps:
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
node-version: "18.x"
registry-url: "https://registry.npmjs.org"
- uses: pnpm/action-setup@v2
with:
version: 8
run_install: false
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Install
run: |
yarn install --no-lockfile
pnpm install
- name: Lint
run: yarn lint
run: pnpm lint
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"start:syncserver": "cross-env DEBUG='WebsocketServer' pnpm -F @automerge/example-sync-server start",
"preinstall": "npx only-allow pnpm",
"repocheck": "manypkg check",
"lint": "lerna run lint",
"lint": "eslint --ext .ts .",
"test": "vitest",
"test:log": "cross-env DEBUG='automerge-repo:*' vitest",
"test:coverage": "vitest --coverage",
Expand All @@ -43,8 +43,8 @@
"@types/react-dom": "^18.0.9",
"@types/uuid": "^8.3.4",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"@vitejs/plugin-react": "^3.0.0",
"@vitest/coverage-v8": "^1.0.1",
"@vitest/ui": "^1.0.1",
Expand All @@ -70,4 +70,4 @@
"vite-plugin-wasm": "^3.2.2",
"vitest": "^1.0.4"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
NetworkAdapter,
type PeerId,
type Message,
type StorageId,
PeerMetadata,
} from "@automerge/automerge-repo"
import { MessagePortRef } from "./MessagePortRef.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
PeerId,
PeerMetadata,
cbor,
isRepoMessage,
} from "@automerge/automerge-repo"
import WebSocket from "isomorphic-ws"

Expand Down
21 changes: 12 additions & 9 deletions packages/automerge-repo-react-hooks/src/useDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ export function useDocument<T>(
}

handleRef.current = handle
handle.doc().then(v => {
// Bail out on updating the doc if the handle has changed since we started loading.
// This avoids problem with out-of-order loads when the handle is changing faster
// than documents are loading.
if (handleRef.current !== handle) {
return
}
setDoc(v)
})
handle
.doc()
.then(v => {
// Bail out on updating the doc if the handle has changed since we started loading.
// This avoids problem with out-of-order loads when the handle is changing faster
// than documents are loading.
if (handleRef.current !== handle) {
return
}
setDoc(v)
})
.catch(e => console.error(e))

const onChange = (h: DocHandleChangePayload<T>) => setDoc(h.doc)
handle.on("change", onChange)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const useLocalAwareness = ({
useEffect(() => {
// Send entire state to new peers
let broadcastTimeoutId
const newPeerEvents = peerEvents.on("new_peer", e => {
const newPeerEvents = peerEvents.on("new_peer", () => {
broadcastTimeoutId = setTimeout(
() => handle.broadcast([userId, localStateRef.current]),
500 // Wait for the peer to be ready
Expand Down
28 changes: 0 additions & 28 deletions packages/automerge-repo/.eslintrc

This file was deleted.

3 changes: 1 addition & 2 deletions packages/automerge-repo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"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 pnpm test",
"test": "vitest",
Expand Down Expand Up @@ -56,4 +55,4 @@
"publishConfig": {
"access": "public"
}
}
}
2 changes: 1 addition & 1 deletion packages/automerge-repo/src/AutomergeUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const urlPrefix = "automerge:"
/** Given an Automerge URL, returns the DocumentId in both base58check-encoded form and binary form */
export const parseAutomergeUrl = (url: AutomergeUrl) => {
const regex = new RegExp(`^${urlPrefix}(\\w+)$`)
const [_, docMatch] = url.match(regex) || []
const [, docMatch] = url.match(regex) || []
const documentId = docMatch as DocumentId
const binaryDocumentId = documentIdToBinary(documentId)

Expand Down
6 changes: 5 additions & 1 deletion packages/automerge-repo/src/Repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ export class Repo extends EventEmitter<RepoEvents> {
if (!handler) {
handler = this.#throttledSaveSyncStateHandlers[storageId] = throttle(
({ documentId, syncState }: SyncStatePayload) => {
this.storageSubsystem!.saveSyncState(documentId, storageId, syncState)
void this.storageSubsystem!.saveSyncState(
documentId,
storageId,
syncState
)
},
this.saveDebounceRate
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class CollectionSynchronizer extends Synchronizer {
}

// TODO: implement this
// eslint-disable-next-line @typescript-eslint/no-unused-vars
removeDocument(documentId: DocumentId) {
throw new Error("not implemented")
}
Expand Down
34 changes: 19 additions & 15 deletions packages/automerge-repo/src/synchronizer/DocSynchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ export class DocSynchronizer extends Synchronizer {

let pendingCallbacks = this.#pendingSyncStateCallbacks[peerId]
if (!pendingCallbacks) {
this.#onLoadSyncState(peerId).then(syncState => {
this.#initSyncState(peerId, syncState ?? A.initSyncState())
}).catch(err => {
this.#log(`Error loading sync state for ${peerId}: ${err}`)
})
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 @@ -262,13 +264,15 @@ export class DocSynchronizer extends Synchronizer {
)
this.#setSyncState(peerId, reparsedSyncState)

docPromise.then(doc => {
if (doc) {
this.#sendSyncMessage(peerId, doc)
}
}).catch(err => {
this.#log(`Error loading doc for ${peerId}: ${err}`)
})
docPromise
.then(doc => {
if (doc) {
this.#sendSyncMessage(peerId, doc)
}
})
.catch(err => {
this.#log(`Error loading doc for ${peerId}: ${err}`)
})
})
})
}
Expand Down Expand Up @@ -330,10 +334,10 @@ export class DocSynchronizer extends Synchronizer {
}

this.#processAllPendingSyncMessages()
this.#processSyncMessage(message, new Date())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

this.#processSyncMessage(message)
}

#processSyncMessage(message: SyncMessage | RequestMessage, received: Date) {
#processSyncMessage(message: SyncMessage | RequestMessage) {
if (isRequestMessage(message)) {
this.#peerDocumentStatuses[message.senderId] = "wants"
}
Expand Down Expand Up @@ -392,7 +396,7 @@ export class DocSynchronizer extends Synchronizer {

#processAllPendingSyncMessages() {
for (const message of this.#pendingSyncMessages) {
this.#processSyncMessage(message.message, message.received)
this.#processSyncMessage(message.message)
}

this.#pendingSyncMessages = []
Expand Down
28 changes: 0 additions & 28 deletions packages/create-repo-node-app/.eslintrc

This file was deleted.

Loading