From 614cbc400caaeec7d1733155804c671592b80eca Mon Sep 17 00:00:00 2001 From: JackUait Date: Sat, 8 Nov 2025 01:46:35 +0300 Subject: [PATCH] fix: lint issues in codex.ts --- src/codex.ts | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/codex.ts b/src/codex.ts index 27d50acd..df0468c7 100644 --- a/src/codex.ts +++ b/src/codex.ts @@ -1,6 +1,6 @@ 'use strict'; -import type { EditorConfig } from '../types'; +import type { EditorConfig, API } from '../types'; /** * Apply polyfills @@ -43,23 +43,24 @@ export default class EditorJS { */ constructor(configuration?: EditorConfig|string) { /** - * Set default onReady function + * Set default onReady function or use the one from configuration if provided */ // eslint-disable-next-line @typescript-eslint/no-empty-function - let onReady = (): void => {}; - - /** - * If `onReady` was passed in `configuration` then redefine onReady function - */ - if (_.isObject(configuration) && _.isFunction(configuration.onReady)) { - onReady = configuration.onReady; - } + const onReady = (_.isObject(configuration) && _.isFunction(configuration.onReady)) + ? configuration.onReady + : () => {}; /** * Create a Editor.js instance */ const editor = new Core(configuration); + /** + * Initialize destroy with a no-op function that will be replaced in exportAPI + */ + // eslint-disable-next-line @typescript-eslint/no-empty-function + this.destroy = (): void => {}; + /** * We need to export isReady promise in the constructor * as it can be used before other API methods are exported @@ -93,11 +94,9 @@ export default class EditorJS { destroyTooltip(); - editor = null; - for (const field in this) { if (Object.prototype.hasOwnProperty.call(this, field)) { - delete this[field]; + delete (this as Record)[field]; } } @@ -105,14 +104,14 @@ export default class EditorJS { }; fieldsToExport.forEach((field) => { - this[field] = editor[field]; + (this as Record)[field] = (editor as unknown as Record)[field]; }); this.destroy = destroy; Object.setPrototypeOf(this, editor.moduleInstances.API.methods); - delete this.exportAPI; + delete (this as Partial).exportAPI; const shorthands = { blocks: { @@ -136,7 +135,10 @@ export default class EditorJS { .forEach(([key, methods]) => { Object.entries(methods) .forEach(([name, alias]) => { - this[alias] = editor.moduleInstances.API.methods[key][name]; + const apiKey = key as keyof API; + const apiMethods = editor.moduleInstances.API.methods[apiKey] as unknown as Record; + + (this as Record)[alias] = apiMethods[name]; }); }); }