diff options
author | James Maa <jmaa@berkeley.edu> | 2024-05-09 15:42:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-09 07:42:35 +0000 |
commit | 13278a5cf67de69678d8c4c5fb97e6eb00c94c11 (patch) | |
tree | 1d77bcf97bb9c6f08c88c9f80ea0da735d5721c2 /ext/js/comm | |
parent | 77fa1d0f64b66d6e4fe9c8795c7844206edbcaf2 (diff) |
Update eslint unsafe rule (#887)
* Enable @typescript-eslint/no-unsafe-assignment
* Updates
* Add missing import
* Updates
* Fix types?
* Fix tests
* Address comments
* Move TextProcessorVariant to types
* Update types/ext/translation-internal.d.ts
Co-authored-by: StefanVukovic99 <stefanvukovic44@gmail.com>
Signed-off-by: James Maa <jmaa@berkeley.edu>
---------
Signed-off-by: James Maa <jmaa@berkeley.edu>
Co-authored-by: toasted-nutbread <toasted-nutbread@users.noreply.github.com>
Co-authored-by: StefanVukovic99 <stefanvukovic44@gmail.com>
Diffstat (limited to 'ext/js/comm')
-rw-r--r-- | ext/js/comm/anki-connect.js | 7 | ||||
-rw-r--r-- | ext/js/comm/frame-ancestry-handler.js | 1 | ||||
-rw-r--r-- | ext/js/comm/frame-client.js | 1 |
3 files changed, 6 insertions, 3 deletions
diff --git a/ext/js/comm/anki-connect.js b/ext/js/comm/anki-connect.js index 6a008f40..23183e79 100644 --- a/ext/js/comm/anki-connect.js +++ b/ext/js/comm/anki-connect.js @@ -18,6 +18,7 @@ import {ExtensionError} from '../core/extension-error.js'; import {parseJson} from '../core/json.js'; +import {isObjectNotArray} from '../core/object-utilities.js'; import {getRootDeckName} from '../data/anki-util.js'; /** @@ -606,15 +607,15 @@ export class AnkiConnect { if (typeof modelName !== 'string') { throw this._createError(`Unexpected result type at index ${i}, field modelName: expected string, received ${this._getTypeName(modelName)}`, result); } - if (typeof fields !== 'object' || fields === null) { - throw this._createError(`Unexpected result type at index ${i}, field fields: expected string, received ${this._getTypeName(fields)}`, result); + if (!isObjectNotArray(fields)) { + throw this._createError(`Unexpected result type at index ${i}, field fields: expected object, received ${this._getTypeName(fields)}`, result); } const tags2 = /** @type {string[]} */ (this._normalizeArray(tags, -1, 'string', ', field tags')); const cards2 = /** @type {number[]} */ (this._normalizeArray(cards, -1, 'number', ', field cards')); /** @type {{[key: string]: import('anki').NoteFieldInfo}} */ const fields2 = {}; for (const [key, fieldInfo] of Object.entries(fields)) { - if (typeof fieldInfo !== 'object' || fieldInfo === null) { continue; } + if (!isObjectNotArray(fieldInfo)) { continue; } const {value, order} = fieldInfo; if (typeof value !== 'string' || typeof order !== 'number') { continue; } fields2[key] = {value, order}; diff --git a/ext/js/comm/frame-ancestry-handler.js b/ext/js/comm/frame-ancestry-handler.js index 39288738..1915f121 100644 --- a/ext/js/comm/frame-ancestry-handler.js +++ b/ext/js/comm/frame-ancestry-handler.js @@ -288,6 +288,7 @@ export class FrameAncestryHandler { } /** @type {?ShadowRoot|undefined} */ + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const shadowRoot = ( element.shadowRoot || // @ts-expect-error - openOrClosedShadowRoot is available to Firefox 63+ for WebExtensions diff --git a/ext/js/comm/frame-client.js b/ext/js/comm/frame-client.js index a30efa29..effd3e7c 100644 --- a/ext/js/comm/frame-client.js +++ b/ext/js/comm/frame-client.js @@ -83,6 +83,7 @@ export class FrameClient { */ _connectInternal(frame, targetOrigin, hostFrameId, setupFrame, timeout) { return new Promise((resolve, reject) => { + /** @type {Map<string, string>} */ const tokenMap = new Map(); /** @type {?import('core').Timeout} */ let timer = null; |