From d48f294edd48d69eba2b8bff39025983c808c686 Mon Sep 17 00:00:00 2001 From: Jonathon Herbert Date: Thu, 9 Jan 2025 14:20:00 +0000 Subject: [PATCH] Lint --- demo/index.ts | 21 ++++++++++++++----- src/plugin/__tests__/plugin.spec.tsx | 1 - .../helpers/__tests__/prosemirror.spec.ts | 7 +++++-- src/plugin/helpers/constants.ts | 2 +- src/plugin/helpers/prosemirror.ts | 8 +++---- src/plugin/plugin.ts | 10 +++++++-- 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/demo/index.ts b/demo/index.ts index b667cb30..befca806 100644 --- a/demo/index.ts +++ b/demo/index.ts @@ -82,7 +82,7 @@ import { import type { WindowType } from "./types"; // Enable collaboration and serialisation. Disabling can be useful when measuring performance improvements. -const enableExpensiveFeatures = false; +const enableExpensiveFeatures = true; // Only show focus when the user is keyboard navigating, not when // they click a text field. @@ -353,6 +353,7 @@ const createEditor = (server: CollabServer) => { } }); + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- for dev use const expensivePlugins = enableExpensiveFeatures ? [ collabPlugin, @@ -508,12 +509,19 @@ const createEditor = (server: CollabServer) => { }); btnContainer.appendChild(toggleImageFields); + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- for dev use if (enableExpensiveFeatures) { - new EditorConnection(view, server, clientID, `User ${clientID}`, (state) => { - if (isFirstEditor) { - set(state.doc); + new EditorConnection( + view, + server, + clientID, + `User ${clientID}`, + (state) => { + if (isFirstEditor) { + set(state.doc); + } } - }); + ); } editorNo++; @@ -524,6 +532,8 @@ const createEditor = (server: CollabServer) => { const server = new CollabServer(); firstEditor = createEditor(server); const doc = firstEditor.state.doc; + +// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- for dev use if (enableExpensiveFeatures) { server.init(doc); } @@ -543,6 +553,7 @@ declare global { interface Window extends WindowType {} } +// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- for dev use if (enableExpensiveFeatures) { applyDevTools(firstEditor); } diff --git a/src/plugin/__tests__/plugin.spec.tsx b/src/plugin/__tests__/plugin.spec.tsx index 5328617a..23f7e61c 100644 --- a/src/plugin/__tests__/plugin.spec.tsx +++ b/src/plugin/__tests__/plugin.spec.tsx @@ -10,7 +10,6 @@ import type { FieldNameToValueMapWithEmptyValues } from "../helpers/fieldView"; import { createEditorWithElements } from "../helpers/test"; import { elementSelectedNodeAttr } from "../nodeSpec"; import type { FieldDescriptions } from "../types/Element"; -import { pluginKey } from "../helpers/constants"; describe("createPlugin", () => { // Called when our consumer is updated by the plugin. diff --git a/src/plugin/helpers/__tests__/prosemirror.spec.ts b/src/plugin/helpers/__tests__/prosemirror.spec.ts index 8bda301c..25da0036 100644 --- a/src/plugin/helpers/__tests__/prosemirror.spec.ts +++ b/src/plugin/helpers/__tests__/prosemirror.spec.ts @@ -1,6 +1,9 @@ -import { defaultPredicate, getValidElementInsertionRange } from "../prosemirror"; -import { doc, example, example__caption } from "./fixtures"; import { Node } from "prosemirror-model"; +import { + defaultPredicate, + getValidElementInsertionRange, +} from "../prosemirror"; +import { doc, example, example__caption } from "./fixtures"; describe("prosemirror utilities", () => { const a = example("", example__caption("a")); diff --git a/src/plugin/helpers/constants.ts b/src/plugin/helpers/constants.ts index a1d38224..398182c5 100644 --- a/src/plugin/helpers/constants.ts +++ b/src/plugin/helpers/constants.ts @@ -2,7 +2,7 @@ // renderers that must be able to uniquely identify children – for example, in import { PluginKey } from "prosemirror-state"; -import { PluginState } from "../plugin"; +import type { PluginState } from "../plugin"; // React, where a `key` attribute is expected in arrays of ReactNodes. export const RepeaterFieldMapIDKey = "__ID"; diff --git a/src/plugin/helpers/prosemirror.ts b/src/plugin/helpers/prosemirror.ts index b9e784d8..37f81046 100644 --- a/src/plugin/helpers/prosemirror.ts +++ b/src/plugin/helpers/prosemirror.ts @@ -149,10 +149,10 @@ export const findAllNodesThatMatchPredicate = ( to: number, predicate: Predicate ) => { - const result: { + const result: Array<{ node: Node; pos: number; - }[] = []; + }> = []; node.nodesBetween(from, to, (iterNode, pos, parent, index) => { if (predicate(iterNode, pos, parent, index)) { result.push({ node: iterNode, pos }); @@ -167,7 +167,7 @@ export const findAllNodesThatMatchPredicate = ( recursion, top-level elements would move inside the list element, often breaking the document structure. Note this still allows us to move nested elements **within** list elements. */ - return !result && !anyDescendantFieldIsNestedElementField(iterNode); + return !anyDescendantFieldIsNestedElementField(iterNode); }); return result; @@ -189,7 +189,7 @@ export const getValidElementInsertionRange = ( predicate ); - if (!validNodes.length) { + if (validNodes.length === 0) { return undefined; } diff --git a/src/plugin/plugin.ts b/src/plugin/plugin.ts index 7dbcf590..05f6641b 100644 --- a/src/plugin/plugin.ts +++ b/src/plugin/plugin.ts @@ -250,7 +250,10 @@ const createNodeView = < let currentDecos = innerDecos; let currentIsSelected = false; const pluginState = pluginKey.getState(view.state); - let currentCommandValues = getCommandValues(getPos(), pluginState?.validInsertionRange); + let currentCommandValues = getCommandValues( + getPos(), + pluginState?.validInsertionRange + ); let currentSelection = view.state.selection; let currentStoredMarks = view.state.storedMarks; @@ -291,7 +294,10 @@ const createNodeView = < const newCommands = commands(getPos, view); const pluginState = pluginKey.getState(view.state); - const newCommandValues = getCommandValues(getPos(), pluginState?.validInsertionRange); + const newCommandValues = getCommandValues( + getPos(), + pluginState?.validInsertionRange + ); const newSelection = view.state.selection; const newStoredMarks = view.state.storedMarks;