Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions collab-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (process.argv.length !== 3) {
process.exit(1)
}

const projectDir = process.argv[2]
const projectDir = process.argv[2]!
const socketPath = path.join(process.cwd(), 'collab.sock')
const dbPath = path.join(process.cwd(), 'collab.db')

Expand Down Expand Up @@ -63,8 +63,9 @@ const server = new Server({
doc.getText(YTEXT_KEY).insert(0, content)
return Y.encodeStateAsUpdate(doc)
},
async store({ documentName, state }) {
store({ documentName, state }) {
Comment thread
Vtec234 marked this conversation as resolved.
upsertDocument(documentName, state)
return Promise.resolve()
},
}),
],
Expand All @@ -84,7 +85,8 @@ server.httpServer.listen(socketPath, () => {
Object.defineProperty(server, 'httpURL', {
get: () => `http+unix:${socketPath}`,
})
server['showStartScreen']()
// Deliberate abstraction violation to call showStartScreen()
;(server as unknown as { showStartScreen(): void }).showStartScreen()

// No need to call `onListen` hooks here since we don't register any.
})
Expand All @@ -96,7 +98,7 @@ console.log('Hocuspocus shutting down..')
await Promise.all(
[...server.hocuspocus.documents.values()].map(async doc => {
try {
await fs.writeFile(checkedToDiskPath(doc.name), doc.getText(YTEXT_KEY).toString())
await fs.writeFile(checkedToDiskPath(doc.name), doc.getText(YTEXT_KEY).toJSON())
Comment thread
Vtec234 marked this conversation as resolved.
console.log(`Saved '${doc.name}' to disk`)
} catch (e) {
console.error(`Failed to save '${doc.name}' to disk:`, e)
Expand Down
44 changes: 42 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import eslint from '@eslint/js'
import { defineConfig, globalIgnores } from 'eslint/config'
import nextVitals from 'eslint-config-next/core-web-vitals'
import nextTs from 'eslint-config-next/typescript'
import prettier from 'eslint-config-prettier/flat'
import noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths'
import simpleImportSort from 'eslint-plugin-simple-import-sort'
import unusedImports from 'eslint-plugin-unused-imports'
import tseslint from 'typescript-eslint'

const eslintConfig = defineConfig([
...nextVitals,
Expand All @@ -15,6 +17,7 @@ const eslintConfig = defineConfig([
// vscode-workbench:
'*/dist/',
'*/.vscode-test/',
'vscode-workbench/src/vscode.proposed.*.d.ts',
// Default ignores of eslint-config-next:
'.next/',
'out/',
Expand All @@ -23,28 +26,65 @@ const eslintConfig = defineConfig([
'branch-*/',
]),
{
extends: [eslint.configs.recommended],
plugins: {
'simple-import-sort': simpleImportSort,
'unused-imports': unusedImports,
},
rules: {
'@typescript-eslint/no-unused-vars': 'off',
'no-unused-vars': ['error', { args: 'none', caughtErrors: 'none' }],
'simple-import-sort/imports': 'warn',
'unused-imports/no-unused-imports': 'warn',
'unused-imports/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
},
},
{
// Typescript rules
files: ['**/*.{mts,ts,tsx}'],
extends: tseslint.configs.recommendedTypeChecked,
languageOptions: { parserOptions: { projectService: true } },
rules: {
'@typescript-eslint/no-unused-vars': ['error', { args: 'none', varsIgnorePattern: '^_', caughtErrors: 'none' }],
'@typescript-eslint/no-misused-promises': [
'error',
{
// these exceptions reduce unnecessary friction with React stuff
checksVoidReturn: {
arguments: false,
attributes: false,
},
},
],
'@typescript-eslint/restrict-template-expressions': 'off', // always allow `${x}` regardless of x's type
'@typescript-eslint/no-confusing-void-expression': ['error', { ignoreArrowShorthand: true }], // allow (x) => console.log(x), ban const x = console.log(x)
'@typescript-eslint/no-unnecessary-condition': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unsafe-member-access': ['error', { allowOptionalChaining: true }], // optional chaining helps with tests
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'error', // complements how strict works in typescript for chained promises
},
},
{
// Rules that only make sense in the app
files: ['src/**/*.{mts,ts,tsx}'],
plugins: { 'no-relative-import-paths': noRelativeImportPaths },
rules: {
'@typescript-eslint/require-await': 'off', // `'use server'` modules must only export async
'no-relative-import-paths/no-relative-import-paths': [
'warn',
{ allowSameFolder: true, rootDir: 'src', prefix: '@' },
],
},
},
{
// Test files may need to make use of the `any` type in a way we want to
// prevent in normal code.
files: ['**/*.{spec,test}.{ts,tsx}', '**/tests/**'],
rules: {
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/unbound-method': 'off',
},
},
])

export default eslintConfig
Loading