From 73169f06dff767020718a5715eba97d3575ba7e1 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 24 Feb 2024 23:47:57 -0500 Subject: Turn on @typescript-eslint/no-unsafe-argument (#728) --- ext/js/data/database.js | 21 ++++++++++++++++----- ext/js/data/options-util.js | 10 ++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'ext/js/data') diff --git a/ext/js/data/database.js b/ext/js/data/database.js index e8575be2..7f37347b 100644 --- a/ext/js/data/database.js +++ b/ext/js/data/database.js @@ -194,7 +194,8 @@ export class Database { request.onsuccess = (e) => { const cursor = /** @type {IDBRequest} */ (e.target).result; if (cursor) { - const {value} = cursor; + /** @type {TResult} */ + const value = cursor.value; if (noPredicate || predicate(value, predicateArg)) { resolve(value, data); } else { @@ -353,7 +354,9 @@ export class Database { for (const {version, stores} of upgrades) { if (oldVersion >= version) { continue; } - for (const [objectStoreName, {primaryKey, indices}] of Object.entries(stores)) { + /** @type {[objectStoreName: string, value: import('database').StoreDefinition][]} */ + const entries = Object.entries(stores); + for (const [objectStoreName, {primaryKey, indices}] of entries) { const existingObjectStoreNames = transaction.objectStoreNames || db.objectStoreNames; const objectStore = ( this._listContains(existingObjectStoreNames, objectStoreName) ? @@ -394,8 +397,14 @@ export class Database { */ _getAllFast(objectStoreOrIndex, query, onSuccess, onReject, data) { const request = objectStoreOrIndex.getAll(query); - request.onerror = (e) => onReject(/** @type {IDBRequest} */ (e.target).error, data); - request.onsuccess = (e) => onSuccess(/** @type {IDBRequest} */ (e.target).result, data); + request.onerror = (e) => { + const target = /** @type {IDBRequest} */ (e.target); + onReject(target.error, data); + }; + request.onsuccess = (e) => { + const target = /** @type {IDBRequest} */ (e.target); + onSuccess(target.result, data); + }; } /** @@ -415,7 +424,9 @@ export class Database { request.onsuccess = (e) => { const cursor = /** @type {IDBRequest} */ (e.target).result; if (cursor) { - results.push(cursor.value); + /** @type {TResult} */ + const value = cursor.value; + results.push(value); cursor.continue(); } else { onSuccess(results, data); diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index 8ef52972..de30f52a 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -22,6 +22,11 @@ import {escapeRegExp, isObject} from '../core/utilities.js'; import {TemplatePatcher} from '../templates/template-patcher.js'; import {JsonSchema} from './json-schema.js'; +// Some type safety rules are disabled for this file since it deals with upgrading an older format +// of the options object to a newer format. SafeAny is used for much of this, since every single +// legacy format does not contain type definitions. +/* eslint-disable @typescript-eslint/no-unsafe-argument */ + export class OptionsUtil { constructor() { /** @type {?TemplatePatcher} */ @@ -119,6 +124,9 @@ export class OptionsUtil { } }); }); + if (typeof optionsStr !== 'string') { + throw new Error('Invalid value for options'); + } options = parseJson(optionsStr); } catch (e) { // NOP @@ -1197,3 +1205,5 @@ export class OptionsUtil { }); } } + +/* eslint-enable @typescript-eslint/no-unsafe-argument */ -- cgit v1.2.3