Skip to content

Commit df73156

Browse files
authored
fix: clean up lint warnings and remove unused code (#754)
* fix: clean up lint warnings and remove unused code * fix: last cleanup
1 parent e4c3c24 commit df73156

88 files changed

Lines changed: 223 additions & 778 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/collaboration-yjs/src/connection-handler/handler.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,25 @@ export class ConnectionHandler {
7373
* Connect some listeners for our hooks, if provided
7474
*/
7575
if (this.#hooks.beforeChange) {
76+
// keeping transaction here for future reference
77+
// eslint-disable-next-line no-unused-vars
7678
sharedDoc.on('beforeTransaction', (transaction) => {
7779
this.#hooks.beforeChange(userParams);
7880
});
7981
}
8082

8183
if (this.#hooks.change) {
84+
// keeping origin here for future reference
85+
// eslint-disable-next-line no-unused-vars
8286
sharedDoc.on('update', (update, origin) => {
8387
this.#hooks.change(userParams);
8488
});
8589
}
8690

87-
socket.on('close', (code, reason) => {
88-
this.#log('🔌 Socket closed, cleaning up connection for', params.documentId);
89-
this.documentManager.releaseConnection(params.documentId, socket);
91+
// eslint-disable-next-line no-unused-vars
92+
socket.on('close', (/** @type {number} */ code, /** @type {Buffer} */ reason) => {
93+
this.#log('🔌 Socket closed, cleaning up connection for', /** @type {string} */ (params.documentId));
94+
this.documentManager.releaseConnection(/** @type {string} */ (params.documentId), socket);
9095
});
9196

9297
/** Initialieze the socket connection */

packages/collaboration-yjs/src/shared-doc/shared-doc.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,24 @@ export class SharedSuperDoc extends YDoc {
6565
debouncer(() => callbackHandler(/** @type {SharedSuperDoc} */ (doc)));
6666
});
6767
}
68-
this.whenInitialized = contentInitializer(this);
68+
69+
this.whenInitialized = contentInitializer();
6970
}
7071
}
7172

7273
/**
73-
* @type {(ydoc: YDoc) => Promise<void>}
74+
* @type {() => Promise<void>}
7475
*/
75-
let contentInitializer = (_ydoc) => Promise.resolve();
76+
let contentInitializer = () => Promise.resolve();
7677

7778
/**
7879
* The main handler for updates to the Yjs document.
7980
* This function encodes the update and sends it to all connected clients.
8081
* @param {Uint8Array} update
8182
* @param {any} _origin
8283
* @param {SharedSuperDoc} doc
83-
* @param {any} _tr
8484
*/
85-
const updateHandler = (update, _origin, doc, _tr) => {
85+
const updateHandler = (update, _origin, doc) => {
8686
const encoder = createEncoder();
8787
writeVarUint(encoder, messageSync);
8888
writeUpdate(encoder, update);
@@ -121,7 +121,7 @@ export const send = (doc, conn, message) => {
121121
conn.send(message, {}, (err) => {
122122
err != null && closeConn(doc, conn);
123123
});
124-
} catch (e) {
124+
} catch {
125125
closeConn(doc, conn);
126126
}
127127
};

packages/super-editor/src/components/toolbar/ai-helpers.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function getJsonBetweenFencesFromResponse(buffer) {
130130
}
131131

132132
return null;
133-
} catch (e) {
133+
} catch {
134134
return null;
135135
}
136136
}
@@ -238,7 +238,7 @@ export async function rewriteStreaming(text, prompt = '', options = {}, onChunk,
238238
}
239239

240240
const message = prompt
241-
? `Rewrite the following text: "${text}". Instructions: ${prompt}`
241+
? `Rewrite the following text: "${text}" using these instructions: ${prompt}`
242242
: `Rewrite the following text: "${text}"`;
243243

244244
const payload = {
@@ -248,7 +248,7 @@ export async function rewriteStreaming(text, prompt = '', options = {}, onChunk,
248248
{
249249
type: 'custom_prompt',
250250
name: 'text_rewrite',
251-
message: `Rewrite the following text: "${text}" using these instructions: ${prompt}`,
251+
message,
252252
},
253253
],
254254
};
@@ -276,7 +276,7 @@ export async function rewrite(text, prompt = '', options = {}) {
276276
}
277277

278278
const message = prompt
279-
? `Rewrite the following text: "${text}". Instructions: ${prompt}`
279+
? `Rewrite the following text: "${text}" using these instructions: ${prompt}`
280280
: `Rewrite the following text: "${text}"`;
281281

282282
const payload = {
@@ -286,7 +286,7 @@ export async function rewrite(text, prompt = '', options = {}) {
286286
{
287287
type: 'custom_prompt',
288288
name: 'text_rewrite',
289-
message: `Rewrite the following text: "${text}" using these instructions: ${prompt}`,
289+
message,
290290
format: [{ value: '' }],
291291
},
292292
],
@@ -306,7 +306,7 @@ const formatRegistry = {
306306
{
307307
name: 'bold',
308308
pattern: /\*\*(.*?)\*\*/g,
309-
transform: (_match, content, _editor) => ({
309+
transform: (_match, content) => ({
310310
type: 'text',
311311
marks: [{ type: 'bold' }],
312312
text: content,
@@ -315,7 +315,7 @@ const formatRegistry = {
315315
{
316316
name: 'italic',
317317
pattern: /\*(.*?)\*/g,
318-
transform: (_match, content, _editor) => ({
318+
transform: (_match, content) => ({
319319
type: 'text',
320320
marks: [{ type: 'italic' }],
321321
text: content,
@@ -324,7 +324,7 @@ const formatRegistry = {
324324
{
325325
name: 'underline',
326326
pattern: /<(?:u|ins)>(.*?)<\/(?:u|ins)>/g,
327-
transform: (_match, content, _editor) => ({
327+
transform: (_match, content) => ({
328328
type: 'text',
329329
marks: [{ type: 'underline' }],
330330
text: content,

packages/super-editor/src/components/toolbar/defaultItems.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,6 @@ export const makeDefaultItems = ({
814814
},
815815
});
816816

817-
const toolbarItemsMobile = [bold, italic, underline, indentRight, indentLeft, search, overflow].map(
818-
(item) => item.name,
819-
);
820-
821817
const copyFormat = useToolbarItem({
822818
type: 'button',
823819
name: 'copyFormat',
@@ -1191,7 +1187,7 @@ export const makeDefaultItems = ({
11911187

11921188
export const setHistoryButtonStateOnUpdate =
11931189
(toolbarItemsRef) =>
1194-
({ editor, transaction }) => {
1190+
({ editor }) => {
11951191
// console.debug('[SuperEditor dev] Document updated', editor);
11961192
// activeEditor = editor;
11971193

packages/super-editor/src/components/toolbar/super-toolbar.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -348,20 +348,18 @@ export class SuperToolbar extends EventEmitter {
348348

349349
/**
350350
* Toggles the ruler visibility
351-
* @param {Object} [_params=null] - Command parameters (not used)
352351
* @returns {void}
353352
*/
354-
toggleRuler: (_params = null) => {
353+
toggleRuler: () => {
355354
this.superdoc.toggleRuler();
356355
},
357356

358357
/**
359358
* Initiates the image upload process
360359
* @async
361-
* @param {Object} [_params=null - Command parameters (not used)
362360
* @returns {Promise<void>}
363361
*/
364-
startImageUpload: async (_params = null) => {
362+
startImageUpload: async () => {
365363
let open = getFileOpener();
366364
let result = await open();
367365

@@ -521,12 +519,11 @@ export class SuperToolbar extends EventEmitter {
521519
/**
522520
* Executes a table-related command
523521
* @param {Object} params - Command parameters
524-
* @param {CommandItem} params.item - The command item
525522
* @param {Object} params.argument - The table command and its parameters
526523
* @param {string} params.argument.command - The specific table command to execute
527524
* @returns {void}
528525
*/
529-
executeTableCommand: ({ item, argument }) => {
526+
executeTableCommand: ({ argument }) => {
530527
if (!argument) return;
531528

532529
let command = argument.command;
@@ -733,8 +730,13 @@ export class SuperToolbar extends EventEmitter {
733730
const linkedStyles = this.activeEditor.converter?.linkedStyles.find(
734731
(style) => style.id === styleIdMark.attrs.styleId,
735732
);
736-
if (linkedStyles && markToStyleMap[item.name.value] in linkedStyles?.definition.styles) {
737-
const linkedStylesItem = linkedStyles?.definition.styles[markToStyleMap[item.name.value]];
733+
if (
734+
linkedStyles &&
735+
linkedStyles.definition &&
736+
linkedStyles.definition.styles &&
737+
markToStyleMap[item.name.value] in linkedStyles.definition.styles
738+
) {
739+
const linkedStylesItem = linkedStyles.definition.styles[markToStyleMap[item.name.value]];
738740
const value = {
739741
[item.name.value]: linkedStylesItem,
740742
};
@@ -815,11 +817,10 @@ export class SuperToolbar extends EventEmitter {
815817
/**
816818
* React to editor transactions. Might want to debounce this.
817819
* @param {Object} params - Transaction parameters
818-
* @param {Object} params.editor - The editor instance (not used)
819820
* @param {Object} params.transaction - The transaction object
820821
* @returns {void}
821822
*/
822-
onEditorTransaction({ editor, transaction }) {
823+
onEditorTransaction({ transaction }) {
823824
if (!transaction.docChanged && !transaction.selectionSet) return;
824825
this.updateToolbarState();
825826
}
@@ -849,7 +850,7 @@ export class SuperToolbar extends EventEmitter {
849850
return this.#interceptedCommands[command]({ item, argument });
850851
}
851852

852-
if (command in this.activeEditor?.commands) {
853+
if (this.activeEditor && this.activeEditor.commands && command in this.activeEditor.commands) {
853854
this.activeEditor.commands[command](argument);
854855
}
855856

@@ -882,14 +883,19 @@ export class SuperToolbar extends EventEmitter {
882883
let command = item.command;
883884
const noArgumentCommand = item.noArgumentCommand;
884885

885-
if (argument === 'none' && noArgumentCommand in this.activeEditor?.commands) {
886+
if (
887+
argument === 'none' &&
888+
this.activeEditor &&
889+
this.activeEditor.commands &&
890+
noArgumentCommand in this.activeEditor.commands
891+
) {
886892
this.activeEditor.commands[noArgumentCommand]();
887893
if (typeof callback === 'function' && noArgumentCallback) callback(argument);
888894
this.updateToolbarState();
889895
return;
890896
}
891897

892-
if (command in this.activeEditor?.commands) {
898+
if (this.activeEditor && this.activeEditor.commands && command in this.activeEditor.commands) {
893899
this.activeEditor.commands[command](argument);
894900
if (typeof callback === 'function') callback(argument);
895901
this.updateToolbarState();

packages/super-editor/src/core/DocxZipper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DocxZipper {
1818
/**
1919
* Get all docx data from the zipped docx
2020
*
21-
* [Content_Types].xml
21+
* [ContentTypes].xml
2222
* _rels/.rels
2323
* word/document.xml
2424
* word/_rels/document.xml.rels
@@ -40,7 +40,7 @@ class DocxZipper {
4040
const mediaObjects = {};
4141
const validTypes = ['xml', 'rels'];
4242
for (const file of files) {
43-
const [_, zipEntry] = file;
43+
const [, zipEntry] = file;
4444

4545
if (validTypes.some((validType) => zipEntry.name.endsWith(validType))) {
4646
const content = await zipEntry.async('string');

packages/super-editor/src/core/Editor.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ export class Editor extends EventEmitter {
175175
*/
176176
isFocused = false;
177177

178-
/**
179-
* CSS styles for the editor
180-
* @private
181-
*/
182-
#css;
183-
184178
options = {
185179
element: null,
186180
selector: null,
@@ -268,9 +262,9 @@ export class Editor extends EventEmitter {
268262
this.setOptions(options);
269263

270264
let modes = {
271-
docx: () => this.#init(this.options),
272-
text: () => this.#initRichText(this.options),
273-
html: () => this.#initRichText(this.options),
265+
docx: () => this.#init(),
266+
text: () => this.#initRichText(),
267+
html: () => this.#initRichText(),
274268
default: () => {
275269
console.log('Not implemented.');
276270
},
@@ -321,10 +315,9 @@ export class Editor extends EventEmitter {
321315
/**
322316
* Initialize the editor with the given options
323317
* @private
324-
* @param {EditorOptions} options - Editor options
325318
* @returns {void}
326319
*/
327-
#init(options) {
320+
#init() {
328321
this.#createExtensionService();
329322
this.#createCommandService();
330323
this.#createSchema();
@@ -386,8 +379,8 @@ export class Editor extends EventEmitter {
386379
* @param {EditorOptions} options - Editor options
387380
* @returns {void}
388381
*/
389-
#initRichText(options) {
390-
if (!options.extensions || !options.extensions.length) {
382+
#initRichText() {
383+
if (!this.options.extensions || !this.options.extensions.length) {
391384
this.options.extensions = getRichTextExtensions();
392385
}
393386

@@ -944,7 +937,7 @@ export class Editor extends EventEmitter {
944937
let doc;
945938

946939
try {
947-
const { mode, fragment, isHeadless, content, loadFromSchema } = this.options;
940+
const { mode, fragment, content, loadFromSchema } = this.options;
948941

949942
if (mode === 'docx') {
950943
if (loadFromSchema) {
@@ -1666,7 +1659,7 @@ export class Editor extends EventEmitter {
16661659
console.debug('🔗 [super-editor] Ending collaboration');
16671660
if (this.options.collaborationProvider) this.options.collaborationProvider.disconnect();
16681661
if (this.options.ydoc) this.options.ydoc.destroy();
1669-
} catch (error) {}
1662+
} catch {}
16701663
}
16711664

16721665
/**
@@ -1691,7 +1684,7 @@ export class Editor extends EventEmitter {
16911684
}
16921685
this.converter.headerEditors.length = 0;
16931686
this.converter.footerEditors.length = 0;
1694-
} catch (error) {}
1687+
} catch {}
16951688
}
16961689

16971690
/**
@@ -1700,7 +1693,7 @@ export class Editor extends EventEmitter {
17001693
* @param {Object} data - Document data
17011694
* @returns {boolean} Whether migrations are needed
17021695
*/
1703-
static checkIfMigrationsNeeded(data) {
1696+
static checkIfMigrationsNeeded() {
17041697
const dataVersion = version || 'initial';
17051698
const migrations = getNecessaryMigrations(dataVersion) || [];
17061699
console.debug('[checkVersionMigrations] Migrations needed:', dataVersion, migrations.length);

packages/super-editor/src/core/InputRule.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,14 @@ export const inputRulesPlugin = ({ editor, rules }) => {
209209
handlePaste(view, event, slice) {
210210
const clipboard = event.clipboardData;
211211
const html = clipboard.getData('text/html');
212-
const text = clipboard.getData('text/plain');
213212

214213
// Allow specialised plugins (e.g., field-annotation) first shot.
215214
const fieldAnnotationContent = slice.content.content.filter((item) => item.type.name === 'fieldAnnotation');
216215
if (fieldAnnotationContent.length) {
217216
return false;
218217
}
219218

220-
return handleClipboardPaste({ editor, view }, html, text);
219+
return handleClipboardPaste({ editor, view }, html);
221220
},
222221
},
223222

@@ -371,10 +370,9 @@ export function sanitizeHtml(html, forbiddenTags = ['meta', 'svg', 'script', 'st
371370
* @param {Editor} params.editor The SuperEditor instance.
372371
* @param {View} params.view The ProseMirror view associated with the editor.
373372
* @param {String} html HTML clipboard content (may be empty).
374-
* @param {String} text Plain text clipboard content (may be empty).
375373
* @returns {Boolean} Whether the paste was handled.
376374
*/
377-
export function handleClipboardPaste({ editor, view }, html, text) {
375+
export function handleClipboardPaste({ editor, view }, html) {
378376
let source;
379377
if (!html) {
380378
source = 'plain-text';

packages/super-editor/src/core/commands/increaseListIndent.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export const increaseListIndent =
88
() =>
99
({ editor, tr }) => {
1010
const { state } = editor;
11-
const $from = state.selection.$from;
1211
const currentNode = ListHelpers.getCurrentListItem(state);
1312
if (!currentNode) return false;
1413

0 commit comments

Comments
 (0)