Add ESLint + pre-commit hook and fix the issues it surfaced

This commit is contained in:
2026-06-05 01:42:42 +03:00
parent 3d38dd1411
commit 939950b136
10 changed files with 1543 additions and 53 deletions
+5 -4
View File
@@ -56,8 +56,9 @@ function tx<T>(
const transaction = db.transaction(store, mode);
const request = run(transaction.objectStore(store));
transaction.oncomplete = () => resolve(request.result);
transaction.onerror = () => reject(transaction.error);
transaction.onabort = () => reject(transaction.error);
const fail = () => reject(transaction.error ?? new Error('IndexedDB transaction failed'));
transaction.onerror = fail;
transaction.onabort = fail;
}),
);
}
@@ -69,10 +70,10 @@ export const getAll = <T>(store: string): Promise<T[]> =>
tx<T[]>(store, 'readonly', (s) => s.getAll() as IDBRequest<T[]>);
export const put = <T>(store: string, value: T): Promise<IDBValidKey> =>
tx<IDBValidKey>(store, 'readwrite', (s) => s.put(value as unknown as Record<string, unknown>));
tx<IDBValidKey>(store, 'readwrite', (s) => s.put(value));
export const del = (store: string, key: IDBValidKey): Promise<undefined> =>
tx<undefined>(store, 'readwrite', (s) => s.delete(key) as IDBRequest<undefined>);
tx<undefined>(store, 'readwrite', (s) => s.delete(key));
/** Test-only: forget the memoized connection so a fresh `openDB` reopens. */
export function _resetDbForTests(): void {
@@ -71,7 +71,11 @@ describe('settings-store · ui.theme', () => {
saveUiTheme('dark');
const stored = JSON.parse(localStorage.getItem(KEY)!);
const stored = JSON.parse(localStorage.getItem(KEY)!) as {
version: number;
ui: { theme: string; previewFitMode: string };
editor: { fontSize: number };
};
expect(stored.ui.theme).toBe('dark');
// Everything else survives — nothing clobbered.
expect(stored.version).toBe(1);
+1 -1
View File
@@ -40,7 +40,7 @@ function readRaw(): StoredSettings {
try {
const raw = localStorage.getItem(KEY);
if (!raw) return {};
const parsed = JSON.parse(raw);
const parsed: unknown = JSON.parse(raw);
return parsed && typeof parsed === 'object' ? (parsed as StoredSettings) : {};
} catch (err) {
console.warn('[settings] failed to read, using defaults', err);