From 68b589a33aa22e30fed49d8012c5e6f68f4b94ab Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Tue, 15 Nov 2022 19:51:00 +0530 Subject: [PATCH] chore: Cleanup, fix theme --- .eslintrc.cjs | 15 ++++- src/lib/components/History/history.test.ts | 30 +++++---- src/lib/components/Theme.svelte | 6 +- src/lib/types.d.ts | 9 +++ src/lib/util/fileLoaders/gist.ts | 73 ++++++++++++---------- src/lib/util/migrations.test.ts | 16 +++-- src/lib/util/persist.ts | 2 +- src/lib/util/serde.ts | 2 +- src/lib/util/state.ts | 29 +++++---- src/lib/util/util.ts | 2 +- 10 files changed, 111 insertions(+), 73 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index cacd0b22..7d5e4573 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -5,7 +5,7 @@ module.exports = { 'eslint:recommended', 'plugin:@typescript-eslint/recommended', // 'plugin:@typescript-eslint/recommended-requiring-type-checking', - // 'plugin:@typescript-eslint/strict', + 'plugin:@typescript-eslint/strict', 'prettier' ], plugins: ['svelte3', 'tailwindcss', '@typescript-eslint', 'es', 'vitest'], @@ -21,8 +21,17 @@ module.exports = { 'tsconfig.json' ], overrides: [ - { files: ['*.svelte'], processor: 'svelte3/svelte3' } - // { files: ['*.ts'], extends: ['plugin:@typescript-eslint/recommended-requiring-type-checking'] } + { files: ['*.svelte'], processor: 'svelte3/svelte3' }, + { + files: ['*.ts'], + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:@typescript-eslint/recommended-requiring-type-checking', + 'plugin:@typescript-eslint/strict', + 'prettier' + ] + } ], settings: { 'svelte3/typescript': () => require('typescript') diff --git a/src/lib/components/History/history.test.ts b/src/lib/components/History/history.test.ts index cdb50830..482de012 100644 --- a/src/lib/components/History/history.test.ts +++ b/src/lib/components/History/history.test.ts @@ -21,9 +21,9 @@ describe('history', () => { type: 'manual' }); - const [manualEntry]: HistoryEntry[] = JSON.parse( - window.localStorage.getItem('manualHistoryStore') - ); + const [manualEntry] = JSON.parse( + window.localStorage.getItem('manualHistoryStore') ?? '[]' + ) as HistoryEntry[]; expect(manualEntry.time).toBe(12345); expect(manualEntry.type).toBe('manual'); @@ -36,7 +36,9 @@ describe('history', () => { type: 'auto' }); - const [autoEntry]: HistoryEntry[] = JSON.parse(window.localStorage.getItem('autoHistoryStore')); + const [autoEntry] = JSON.parse( + window.localStorage.getItem('autoHistoryStore') ?? '[]' + ) as HistoryEntry[]; expect(autoEntry.time).toBe(54321); expect(autoEntry.type).toBe('auto'); @@ -101,19 +103,23 @@ describe('history migration', () => { 'autoHistoryStore', '[{"state":{"code":"graph TD\\n A[New Year] -->|Get money| B(Go shopping)","mermaid":"{\\n \\"theme\\": \\"dark\\"\\n}","autoSync":true,"updateDiagram":false},"time":0,"type":"auto","name":"barking-dog"},{"state":{"code":"graph TD\\n A[Christmas] -->|Get money| B(Go shopping)","mermaid":"{\\n \\"theme\\": \\"dark\\"\\n}","autoSync":true,"updateDiagram":true},"time":0,"type":"manual","name":"needy-mosquito"}]' ); - let manualHistoryStore: HistoryEntry[] = JSON.parse( - window.localStorage.getItem('manualHistoryStore') - ); - let autoHistoryStore: HistoryEntry[] = JSON.parse( - window.localStorage.getItem('autoHistoryStore') - ); + let manualHistoryStore = JSON.parse( + window.localStorage.getItem('manualHistoryStore') ?? '[]' + ) as HistoryEntry[]; + let autoHistoryStore = JSON.parse( + window.localStorage.getItem('autoHistoryStore') ?? '[]' + ) as HistoryEntry[]; expect(manualHistoryStore.every(({ id }) => id !== undefined)).toBe(false); expect(autoHistoryStore.every(({ id }) => id !== undefined)).toBe(false); injectHistoryIDs(); - manualHistoryStore = JSON.parse(window.localStorage.getItem('manualHistoryStore')); - autoHistoryStore = JSON.parse(window.localStorage.getItem('autoHistoryStore')); + manualHistoryStore = JSON.parse( + window.localStorage.getItem('manualHistoryStore') ?? '[]' + ) as HistoryEntry[]; + autoHistoryStore = JSON.parse( + window.localStorage.getItem('autoHistoryStore') ?? '[]' + ) as HistoryEntry[]; expect(manualHistoryStore.every(({ id }) => id !== undefined)).toBe(true); expect(autoHistoryStore.every(({ id }) => id !== undefined)).toBe(true); }); diff --git a/src/lib/components/Theme.svelte b/src/lib/components/Theme.svelte index cb5ce1a1..ba35753e 100644 --- a/src/lib/components/Theme.svelte +++ b/src/lib/components/Theme.svelte @@ -24,10 +24,6 @@ '💎 luxury', '🧛‍♂️ dracula' ]; - - function checkTheme(theme: string): boolean { - return $themeStore.theme !== undefined && theme.includes($themeStore.theme); - }