From 2ce3df033290792ef6459a0a7391e09ef367cfc4 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Tue, 10 May 2022 12:37:34 +0200 Subject: [PATCH] Fix lint issues --- .eslintrc.js => .eslintrc.cjs | 4 ++++ src/cache.ts | 32 ++++++++++++++++---------------- src/scripts/search.ts | 9 ++++----- src/utils.ts | 4 +++- 4 files changed, 27 insertions(+), 22 deletions(-) rename .eslintrc.js => .eslintrc.cjs (83%) diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 83% rename from .eslintrc.js rename to .eslintrc.cjs index e88fad1..b6af495 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -19,7 +19,9 @@ module.exports = { "no-param-reassign": "off", "no-alert": "off", "no-console": "off", + "no-shadow": "off", "func-names": "off", + "default-param-last": "off", "dot-notation": ["error", { allowPattern: "^[A-Z][a-z]+$" }], "@typescript-eslint/ban-ts-comment": [ "error", @@ -27,5 +29,7 @@ module.exports = { "ts-expect-error": "allow-with-description", }, ], + "@typescript-eslint/no-shadow": ["error"], + "@typescript-eslint/default-param-last": ["error"], }, }; diff --git a/src/cache.ts b/src/cache.ts index 416e55c..c8a6d32 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -8,6 +8,7 @@ interface CacheEntry { export class Store { readonly dbp: Promise; + // eslint-disable-next-line default-param-last constructor(dbName = "tg-cache", readonly storeName = "keyval") { this.dbp = new Promise((resolve, reject) => { const openreq = indexedDB.open(dbName, 1); @@ -51,8 +52,8 @@ export function get( ): Promise> { let req: IDBRequest; return store - .withIDBStore("readonly", (store) => { - req = store.get(key); + .withIDBStore("readonly", (idbstore) => { + req = idbstore.get(key); }) .then(() => req.result); } @@ -63,8 +64,8 @@ export function set( version: string, store = getDefaultStore() ): Promise { - return store.withIDBStore("readwrite", (store) => { - store.put({ version, value }, key); + return store.withIDBStore("readwrite", (idbstore) => { + idbstore.put({ version, value }, key); }); } @@ -72,14 +73,14 @@ export function del( key: IDBValidKey, store = getDefaultStore() ): Promise { - return store.withIDBStore("readwrite", (store) => { - store.delete(key); + return store.withIDBStore("readwrite", (idbstore) => { + idbstore.delete(key); }); } export function clear(store = getDefaultStore()): Promise { - return store.withIDBStore("readwrite", (store) => { - store.clear(); + return store.withIDBStore("readwrite", (idbstore) => { + idbstore.clear(); }); } @@ -87,16 +88,15 @@ export function keys(store = getDefaultStore()): Promise { const dbkeys: IDBValidKey[] = []; return store - .withIDBStore("readonly", (store) => { + .withIDBStore("readonly", (idbstore) => { // This would be store.getAllKeys(), but it isn't supported by Edge or Safari. // And openKeyCursor isn't supported by Safari. - (store.openKeyCursor || store.openCursor).call( - store - ).onsuccess = function () { - if (!this.result) return; - dbkeys.push(this.result.key); - this.result.continue(); - }; + (idbstore.openKeyCursor || idbstore.openCursor).call(idbstore).onsuccess = + function () { + if (!this.result) return; + dbkeys.push(this.result.key); + this.result.continue(); + }; }) .then(() => dbkeys); } diff --git a/src/scripts/search.ts b/src/scripts/search.ts index da10c2c..875fad0 100644 --- a/src/scripts/search.ts +++ b/src/scripts/search.ts @@ -30,8 +30,8 @@ export function searchBox(): HTMLElement { const jumpTo = (entry: SearchEntry) => { // If page is different jump to that if (global) { - const currentPage = document.querySelector(".page.active") - .dataset.tab; + const currentPage = + document.querySelector(".page.active").dataset.tab; if (currentPage !== entry.page) { TabManager.instance.setActive(entry.page); } @@ -193,9 +193,8 @@ export function searchBox(): HTMLElement { return; default: if (sel.value !== oldValue) { - const currentPage = document.querySelector( - ".page.active" - ); + const currentPage = + document.querySelector(".page.active"); search(sel.value, currentPage.dataset.tab); oldValue = sel.value; } diff --git a/src/utils.ts b/src/utils.ts index 2dc1240..4bc223f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,7 @@ export function nextAnimationFrame(): Promise { - return new Promise((resolve) => requestAnimationFrame(() => resolve())); + return new Promise((resolve) => { + requestAnimationFrame(() => resolve()); + }); } export function delay(ms: number): Promise {